daydreamer Posted October 19, 2008 Share Posted October 19, 2008 I have a date in this format "2008-09-25 16:00:41"; and also a date in this format "Thu Oct 16 22:07:22 BST 2008" and i need to find out how much time has passed between each one in seconds. If two mintues have passed I need to do one thing, if not, then do another thing in my script. The way im going to do this is using mktime() on each date, then $newestdate-$oldest mktime takes input like this mktime(21, 38, 50, 10, 19, 2008) (hour, min, sec, month, day, year) Anyway what is the best way to get my dates into the mktime format, and am i going the right way about this? I was going to use explode(), but it only takes one delimiter as an argument. Quote Link to comment Share on other sites More sharing options...
Guest Posted October 19, 2008 Share Posted October 19, 2008 You can use strtotime() // Returns a unix timestamp $tsA = strtotime('2008-09-25 16:00:41'); $tsB = strtotime('Thu Oct 16 22:07:22 BST 2008'); $diff = $tsB - $tsA; $diff_in_minutes = $diff / 60; if( $diff_in_minutes > 2 ) { // chuck norris! } Hope that's what you meant! Quote Link to comment Share on other sites More sharing options...
daydreamer Posted October 19, 2008 Author Share Posted October 19, 2008 yeh thats exactly what i meant cheers! lmao @ chuck norris. confused me for a second when i saw it. anyway just tried it out, got a minor problem: $date=strtotime("2008-09-25 16:00:41"); echo $date."<br>"; echo mktime(16, 00, 41, 09, 25, 2008)."<br>"; echo date('G, i, s, m, d, Y', mktime(16, 00, 41, 09, 25, 2008))."<br>"; echo date('G, i, s, m, d, Y', $date)."<br>"; output: 1222358441 1198598441 16, 00, 41, 12, 25, 2007 16, 00, 41, 09, 25, 2008 shouldent these be the same? I cant find where im going wrong. Quote Link to comment Share on other sites More sharing options...
daydreamer Posted October 19, 2008 Author Share Posted October 19, 2008 ok fixed it, i dont know what was up with the code above, but the code u supplied worked well. thanks Quote Link to comment Share on other sites More sharing options...
Barand Posted October 19, 2008 Share Posted October 19, 2008 an number begining with 0, eg 07, is taken to be octal ( and 09 is illegal as octal and therefore upsetting things) try <?php $date=strtotime("2008-09-25 16:00:41"); echo $date."<br>"; echo mktime(16, 0, 41, 9, 25, 2008)."<br>"; echo date('G, i, s, m, d, Y', mktime(16, 0, 41, 9, 25, 2008))."<br>"; echo date('G, i, s, m, d, Y', $date)."<br>"; ?> Quote Link to comment Share on other sites More sharing options...
daydreamer Posted November 11, 2008 Author Share Posted November 11, 2008 ah right, thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.