3

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

CLiown
  • 13,665
  • 48
  • 124
  • 205

2 Answers2

5

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 G.
  • 3,036
  • 1
  • 26
  • 27
  • how can we convert the date into unix time. – Rafee May 23 '12 at 12:40
  • `strtotime` already returns a UNIX timestamp. – Matěj G. May 24 '12 at 17:47
  • @Matej Grabovsky : I have tried on todays with converstion to unix and human readable date format. here is the link http://codepad.org/jGD0Y3Qe , dont why? i did something wrong. can you help me out. – Rafee May 25 '12 at 07:02
1

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
  • 15,403
  • 1
  • 27
  • 41