0

Possible Duplicate:
Converting string to MySQL timestamp format in php

Given a date in the following format, how would I convert it into a MySQL TIMESTAMP format in PHP?

Tue, 06 Dec 2011 16:47:11 +0000

I found a similar question, but am having some difficulty in converting it into what I need.

2
  • @hakre - I referenced that question above already; this is a related, but different, question Commented Jan 20, 2012 at 22:05
  • @hakre - I accepted the answer because it explained what I needed. As already stated, it is different (though similar, and I never said "oh but so different" - please do not put words in my mouth I neither said nor intended). Commented Jan 20, 2012 at 22:21

1 Answer 1

5

date('Y-m-d H:i:s',strtotime('Tue, 06 Dec 2011 16:47:11 +0000'))

that's 'canonical' form, but MySQL will also accept

date('YmdHis',strtotime('Tue, 06 Dec 2011 16:47:11 +0000'))

(more details about that format: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-literals.html )

Sign up to request clarification or add additional context in comments.

3 Comments

thanks - there's the conversion I needed :) .. I thought strtotime needed the 'now()' call, or another time to use as a base
+1 because I never knew MySQL would accept YmdHis instead of Y-m-d H:i:s.
@drrcknlsn: take a look at dev.mysql.com/doc/refman/5.5/en/date-and-time-literals.html then for some more interesting stuff

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.