cgm225 Posted September 11, 2008 Share Posted September 11, 2008 If I have a variable, lets say $time, and it contains a timestamp in the following format for example, 2008-09-09 22:31:14, how can I check if the timestamp is greater than two minutes old? Link to comment https://forums.phpfreaks.com/topic/123802-checking-if-timestamp-is-2-minutes-old/ Share on other sites More sharing options...
BlueSkyIS Posted September 11, 2008 Share Posted September 11, 2008 $time = strtotime($time); if (($time - time()) > 120) { // $time is greater than 2 minutes ago. } Link to comment https://forums.phpfreaks.com/topic/123802-checking-if-timestamp-is-2-minutes-old/#findComment-639214 Share on other sites More sharing options...
Caesar Posted September 11, 2008 Share Posted September 11, 2008 <?php function ChceckTime($time, $mins) { $stamp = strtotime($time); $mins = ($mins * 60); if((time() - $stamp) > $mins) return false; else return true; } if(CheckTime($mystamp, 2)) echo'Dude its fine. Not greater than 2 mins.'; else echo'Danger Will Robinson! Danger!!!'; ?> Link to comment https://forums.phpfreaks.com/topic/123802-checking-if-timestamp-is-2-minutes-old/#findComment-639217 Share on other sites More sharing options...
cgm225 Posted September 11, 2008 Author Share Posted September 11, 2008 If my format is 2008-09-09 22:31:14, do I need to strip out the date first? If so, how? Link to comment https://forums.phpfreaks.com/topic/123802-checking-if-timestamp-is-2-minutes-old/#findComment-639243 Share on other sites More sharing options...
BlueSkyIS Posted September 11, 2008 Share Posted September 11, 2008 If my format is 2008-09-09 22:31:14, do I need to strip out the date first? no. Link to comment https://forums.phpfreaks.com/topic/123802-checking-if-timestamp-is-2-minutes-old/#findComment-639257 Share on other sites More sharing options...
cgm225 Posted September 11, 2008 Author Share Posted September 11, 2008 The following does not work for me... $time = $this->data[$id]['timestamp']; //Variable with timestamp in this format: 2008-09-11 14:11:30 $mins = 2; $stamp = strtotime($time); $mins = ($mins * 60); if((time() - $stamp) > $mins) { echo 'Dude its fine. Not greater than 2 mins.'; } else { echo 'Danger Will Robinson! Danger!!!'; } What am I doing wrong? Link to comment https://forums.phpfreaks.com/topic/123802-checking-if-timestamp-is-2-minutes-old/#findComment-639266 Share on other sites More sharing options...
BlueSkyIS Posted September 11, 2008 Share Posted September 11, 2008 if((time() - $stamp) > $mins) { should be if((time() - $stamp) <= $mins) { Link to comment https://forums.phpfreaks.com/topic/123802-checking-if-timestamp-is-2-minutes-old/#findComment-639272 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.