tags:

views:

58

answers:

1

Hello all

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

+5  A: 

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

Michael Goldshteyn
As an easy work around you can try `Zend_Date`
prodigitalson
@prodigitalson - Thanks. Also I found this function `strtotime()` which I am using now.
ShiVik