Jump to content

[SOLVED] Help with time comparison


EchoFool

Recommended Posts

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

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

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.