Belmark Caday
Belmark Caday

Reputation: 1683

is DateTime a pre-defined function or method in php?

guys im helping someone with his php code. but i cant seem to figure out whats wrong with this code:

enter image description here

the system is fine in LOCALHOST. but when i uploaded it to a free hosting (000webhost.com) it gives me this error:

"Fatal error: Call to undefined method DateTime::add() in /home/a5927002/public_html/thesis2/lib/functions.php on line 273"

so i look for a function or class DateTime, i cant find it anywhere. but its working fine in localhost. any ideas guys?

Upvotes: 0

Views: 177

Answers (1)

MIIB
MIIB

Reputation: 1849

I think your local compiled with php 5.3 or greater but your shared host is compiled with php 5.2 or lower.You need PHP version 5.3.0 or higher for the add function. See the following link for more info:

DateTime

DateTime::modify() is an alternative when using PHP 5.2 (php.net). For example you can add 1 day to a specific date using modify function:

$date = date_create('2006-12-12');
date_modify($date, '+1 day');
echo date_format($date, 'Y-m-d');

Upvotes: 2

Related Questions