EchoFool Posted July 18, 2008 Share Posted July 18, 2008 I have two time stamps one from a database and one which is "now". I was wondering if there was a way to compare the two to find out if the gap between them is greater than 20 minutes. These are the two fields <?php $Date = $row['SkipDate']; // from database $Date2 = date("Y-m-d H:i:s",time()); // now time ?> Is it a possible thing to do ? Link to comment https://forums.phpfreaks.com/topic/115419-solved-help-with-time-comparison/ Share on other sites More sharing options...
kenrbnsn Posted July 18, 2008 Share Posted July 18, 2008 You get the UNIX timestamp of each field, subtract them, and compare the result to 1200 (20mins * 60secs). <?php $dt = strtotime($row['SkipData']); // this assumes the field is a normal date/time $dn = time(); $x = abs($dt - $dn); if ($x > 1200) echo "more than 20 minutes between the two dates"; ?> Ken Link to comment https://forums.phpfreaks.com/topic/115419-solved-help-with-time-comparison/#findComment-593357 Share on other sites More sharing options...
unkwntech Posted July 18, 2008 Share Posted July 18, 2008 Try this <?php $date = $row['SkipDate']; if($date > date('Y-m-d H:i:s', mktime('', date('i') +20)) { //more then 20 minutes. } ?> Link to comment https://forums.phpfreaks.com/topic/115419-solved-help-with-time-comparison/#findComment-593363 Share on other sites More sharing options...
kenrbnsn Posted July 18, 2008 Share Posted July 18, 2008 That probably won't work since you're comparing ASCII strings, not integers. This would also work: <?php if (strtotime($row['SkipDate']) > strtotime('+20 minutes')) echo "Greater that 20 minutes"; ?> Ken Link to comment https://forums.phpfreaks.com/topic/115419-solved-help-with-time-comparison/#findComment-593366 Share on other sites More sharing options...
unkwntech Posted July 18, 2008 Share Posted July 18, 2008 I have used this with success before, although I will admit it may have been a bit different... I will have to try and find that code. Link to comment https://forums.phpfreaks.com/topic/115419-solved-help-with-time-comparison/#findComment-593369 Share on other sites More sharing options...
EchoFool Posted July 18, 2008 Author Share Posted July 18, 2008 Thank you for your replies guys! I will give your suggestion a try Ken. Thank you. Link to comment https://forums.phpfreaks.com/topic/115419-solved-help-with-time-comparison/#findComment-593370 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.