PHP Timestamp Hell - Converting ISO8601 timestamps
I hate messing with dates and times in all languages so I hope this helps someone speed along their day:
function tstamptotime($tstamp) {
// converts ISODATE to unix date
// 1984-09-01T14:21:31Z
sscanf($tstamp,"%u-%u-%uT%u:%u:%uZ",$year,$month,$day,
$hour,$min,$sec);
$newtstamp=mktime($hour,$min,$sec,$month,$day,$year);
return $newtstamp;
}
It converts an ISO8601 timestamp to a unix epoch (seconds past whenever unix started counting seconds).
Enjoy.


Yeah, I agree, fiddling with date conversions stinks. At least you didn't have to check your server to see whether it observes daylight savings time (only works on Linux, Windows barfs, btw).
Posted by: Todd | Oct 04, 2005 at 10:15 AM
Wow cheers, just what i was looking for. I also find all these time formats a royal pain in the back side, and a xml feed i use to keep a project of mine running desided to change from a unix time stamp to the ISO format, messing my entire project up...
All working again now...
Thanks
Posted by: Neil Wattam | Apr 04, 2007 at 06:28 AM
Thank you Idealog + Google!
Posted by: Andrew Somervell | Apr 09, 2007 at 11:37 PM
Seems that strtotime() makes it also.
Posted by: Olivier G. | Dec 06, 2007 at 05:14 AM
Thanks! Handy function.
Posted by: djodin | Jul 06, 2008 at 09:49 AM
This was really helpful, thanks.
Posted by: Mike | Jul 29, 2009 at 09:04 AM
That was extremely useful! Thanks
Posted by: jason | Jun 04, 2010 at 02:05 PM
Thanks! This was very helpful.
Posted by: Bradford | Aug 16, 2010 at 05:25 PM
That's saved me about 3 hours of pulling my hair out :) Thanks!
Posted by: Darren | Sep 12, 2010 at 09:26 AM