Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating new Date Time from string

Tags:

php

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 
like image 549
aherlambang Avatar asked May 26 '13 09:05

aherlambang


1 Answers

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'); 
like image 96
craig1231 Avatar answered Oct 04 '22 21:10

craig1231