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
According to http://www.php.net/manual/en/datetime.formats.date.php
It's mm/dd/yyyy, which is American, not British
Use
DateTime::createFromFormat('d/m/Y', '23/05/2013');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With