Jump to content

string date to timestamp


thescientist

Recommended Posts

Given the below date as a string in PHP

Tue, 07 Jun 2011 14:16:37 -0400
does anyone know the simplest way I can get that into a timestamp for sorting purposes? I'm looking into the various PHP date methods but am trying to avoid having to explode or break apart the string, and hopefully I'm just tired and not looking closely enough. :)Thanks in advance.
Link to comment
Share on other sites

How about strtotime()?
I saw that but from the examples I wasn't sure if it would work for my situation. I actually figured it out though, using date_parse.
var_dump($messageHeaders['EmailDate']);echo '<br>';var_dump(date_parse($messageHeaders['EmailDate']));$date = date_parse($messageHeaders['EmailDate']);$stamp = mktime($date['hour'],$date['minute'],$date['second'],$date['month'],$date['day'],$date['year']);echo '<br>';echo $stamp;

edit: well technically my co-worker suggested date_parse... :)

Link to comment
Share on other sites

They do print out two slightly different timestamps and formatted dates (formatted using date('m/d/Y g:i:s', $stamp) ).strtotime()130747059706/07/2011 6:16:37vsdate_parse()130745619706/07/2011 2:16:37I think your date_parse() technique is omitting the timezone thing (-0400)(I think that's the timezone, isn't it?)

Link to comment
Share on other sites

They do print out two slightly different timestamps and formatted dates (formatted using date('m/d/Y g:i:s', $stamp) ).strtotime()130747059706/07/2011 6:16:37vsdate_parse()130745619706/07/2011 2:16:37I think your date_parse() technique is omitting the timezone thing (-0400)(I think that's the timezone, isn't it?)
yeah, that's the time zone. I wasn't sure if it was crucial to the cause, but will most likely need to be considered. Good call on strtotime. Probably go with that. :)
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...