xProteuSx Posted December 13, 2012 Share Posted December 13, 2012 I am having trouble finding the time between two timestamps. I have tried to research this, but I don't even understand this timestamp format. This is the format for the data I am given (I have no choice in this!): 2012-12-13T11:34:16.771Z I don't even know what the T and Z stand for! .. and I can't seem to figure it out. I have a second date to compare to this. For example: 2012-12-13T12:04:29.000Z I have to figure out the difference in days, hours, minutes, and seconds. There must be a php function that can return the difference, if only in seconds (I can handle it from there). Any ideas? Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/271949-difference-in-time-between-timestamps/ Share on other sites More sharing options...
Christian F. Posted December 13, 2012 Share Posted December 13, 2012 The "Z" stands for "Zulu", or otherwise known as GMT+0. The "T" is just syntactical sugar, to separate the date and time aspect of the timestamp. That format is otherwise known as ISO 8601. Though, to easily calculate the differences between these two timestamps, I'd use the DateTime class. Link to comment https://forums.phpfreaks.com/topic/271949-difference-in-time-between-timestamps/#findComment-1399131 Share on other sites More sharing options...
xProteuSx Posted December 13, 2012 Author Share Posted December 13, 2012 Awesome, thanks for the pointer. I was trying to follow this: http://forums.phpfreaks.com/topic/96654-ebay-time/page__hl__+ebay%20+timestamp#entry494620 Link to comment https://forums.phpfreaks.com/topic/271949-difference-in-time-between-timestamps/#findComment-1399132 Share on other sites More sharing options...
xProteuSx Posted December 13, 2012 Author Share Posted December 13, 2012 Man, this timestamp is ridiculous (I am a noob). Here is what I have tried to do: $endtime = 2012-12-13T12:36:59.000Z; $curtime = 2012-12-13T12:12:44.723Z; Find the difference (the difference should be around 25min); Here is what I have tried: $endtime = strtotime($endtime); $curtime = strtotime($curtime); echo date_sub($auc_endtime,$ebaytime); The issue is that I get the following error: Warning: date_sub() expects parameter 1 to be DateTime, integer given Should I be using date_parse? The issue for me is that I have to use something lightweight. I am comparing two timestamps; one is from eBay so I have to make an API call which delays my page loading time, the other is a timestamp from a database. The whole point is to speed up the process of calculating days, hours, minutes, and seconds between these timestamps. Link to comment https://forums.phpfreaks.com/topic/271949-difference-in-time-between-timestamps/#findComment-1399136 Share on other sites More sharing options...
xProteuSx Posted December 13, 2012 Author Share Posted December 13, 2012 Think I've got it figured out: $auctime = date_parse($endtime); $ebaytime = date_parse($curtime); if (($auctime["month"] <= $ebaytime["month"]) && ($auctime["day"] <= $ebaytime["day"]) && ($auctime["hour"] <= $ebaytime["hour"]) && ($auctime["minute"] <= $ebaytime["minute"]) && ($auctime["second"] <= $ebaytime["second"])) {//auction is over} ... seems to be getting it done. Link to comment https://forums.phpfreaks.com/topic/271949-difference-in-time-between-timestamps/#findComment-1399138 Share on other sites More sharing options...
kicken Posted December 13, 2012 Share Posted December 13, 2012 You should be using the DateTime class (or date_create if you want to stick procedural). Also you want to be using the DateTime::diff/date_diff function, not sub. $d1 = new DateTime($endtime); $d2 = new DateTime($curtime); $diff = $d1->diff($d2); var_dump($diff); Link to comment https://forums.phpfreaks.com/topic/271949-difference-in-time-between-timestamps/#findComment-1399141 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.