Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

call to undefined method DateTime::add method in php

Tags:

php

datetime

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

like image 808
vikmalhotra Avatar asked Oct 15 '10 01:10

vikmalhotra


1 Answers

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

like image 111
Michael Goldshteyn Avatar answered Sep 23 '22 21:09

Michael Goldshteyn