aherlambang aherlambang - 1 year ago 68
PHP Question

creating new Date Time from string

I have a string which is:


and I wanted to create a new Date Time object from this, so I did:

new \DateTime('23/05/2013');

Any idea why I am getting this error all the time:

DateTime::__construct(): Failed to parse time string (23/05/2013) at position 0 (2): Unexpected character

Answer Source

According to http://www.php.net/manual/en/datetime.formats.date.php

Its mm/dd/yyyy, which is American, not British


DateTime::createFromFormat('d/m/Y', '23/05/2013');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download