vikmalhotra
vikmalhotra

Reputation: 10071

call to undefined method DateTime::add method in php

I am using php 5.2.9 as a part of xampp installation. I am using codeigniter framework for my webapp. When I call upon DateTime::add, the Call to undefined method error is displayed. My code is...

$date_now = new DateTime();
$formatted_date = $date_now->format('Y-m-d H:i:s');
$expiry_date = $date_now->add(new DateInterval('P1Y'));

The error being displayed is...

 Fatal error: Call to undefined method DateTime::add() in C:\webapps\first\system\application\models\model_first.php on line 25

How can I resolve this? The DateTime::format method works fine here.

Regards

Upvotes: 8

Views: 19625

Answers (1)

Michael Goldshteyn
Michael Goldshteyn

Reputation: 74390

I think you minimally need PHP version 5.3.0 or higher for the add function. See the following link for more info: PHP manual - DateTime::add

Upvotes: 11

Related Questions