PHP DateTime Update
I'm using PHP > 5.3 and i have a question in respect of DateTime:
First i'm not able to use:
$date = new DateTime('2012-06-08 00:00:00');
$t = $date->createFromFormat('Y/m/d', '2012-06-11 23:59:59');
I get the following error message:
Call to undefined method DateTime::createFromFormat()
I can use other function in that class.
The second thing i'm puzzled about how to update the object initial date, or do i have to create a new object?
Answer:
createFromFormat
is a static method of DateTime
so you would need to call it like:$t = DateTime::createFromFormat('Y-m-d', '2012-06-11');
You can update the initial
$date
object by doing:$date = DateTime::createFromFormat('Y-m-d', '2012-06-11');
http://stackoverflow.com/questions/10998331/php-datetime-update?answertab=votes#tab-top
COMMENTS