tags:

views:

47

answers:

2

Is there an easy way to convert date and time like this:

Sun, 14 Mar 2010 09:00:00 GMT

To this format:

20100306T153626

in PHP

+1  A: 

You want the date function. The format string for 20100306T153626 is:

YmdTHis

i.e.

date("Ymd\THis");

for the current date/time. If you want to use your own time, you'll need it as a Unix timestamp, which you can use the mktime function for that.

Andy Shellam
+3  A: 

Use the strtotime and date functions.

$result = date('Ymd\THis', strtotime('Sun, 14 Mar 2010 09:00:00 GMT'));

The “T” has to be escaped, because it has special meaning (timezone abbreviation).

Matěj Grabovský