0

I am trying to convert a date that I parse from a file "September 2, 1904" . How can I convert that to MySQL date format for be able to insert it in MySQL? If insert it like this i get "0000-00-00" in MySQL

I tried something like :

$date = DateTime::createFromFormat('j-M-Y', $data[11]);
            //echo $date->format('Y-m-d');

Thanks in advance

2
  • Just use strtotime. Commented Feb 17, 2016 at 22:54
  • If you use createFromFormat, you have to make the format match the date that you read from the file. j-M-Y is for 2-09-1904, not September 2, 1904. Commented Feb 17, 2016 at 22:55

2 Answers 2

2

I usually rely on strtotime to parse dates if the format can be trusted...

echo date("Y-m-d",strtotime("September 2, 1904"));
Sign up to request clarification or add additional context in comments.

1 Comment

please also mark as answered as other users of SO can learn from it or can see that it is resolved.
0

I think you're looking for something like this?

mktime(0,0,0,9,2,1904)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.