aherlambang aherlambang - 5 months ago 9
PHP Question

creating new Date Time from string

I have a string which is:

'23/05/2013'


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

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

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

Use

DateTime::createFromFormat('d/m/Y', '23/05/2013');