2

Hi I have a few dates coming in random formats:

    Wed, 16 Mar 2011 15:27:48 +0000

or

2011-03-16T17:42:05+0000

and I need to be able to convert them into Unix time in PHP. I assume I need to use mktime() , ,but how do I format my mktime ? I'm having trouble understanding the examples in the manual :/

Thanks

BobFlemming
  • 2,040
  • 11
  • 43
  • 59

2 Answers2

4

strtotime() can work, but if the dates you're passing in are ambiguous (what is 01/02/03? Feb 1st, '03? Mar 2 '01?) it'll turn around and chew you a new one.

Safest option is to use date_create_from_format(), which lets you specify an explicit format for the input.

Marc B
  • 356,200
  • 43
  • 426
  • 500
  • At least the two example formats work fine with `strtotime` and remove the need to try out multiple *possible* formats if you don't know in what format the date is.. – poke Mar 16 '11 at 19:30
1

strtotime

poke
  • 369,085
  • 72
  • 557
  • 602