prakash Posted January 21, 2008 Share Posted January 21, 2008 How can I store current time stamp to database and check if the difference of two time stamp is 10minutes or not. Link to comment https://forums.phpfreaks.com/topic/86993-storing-timestamp-and-finding-the-difference/ Share on other sites More sharing options...
prakash Posted January 21, 2008 Author Share Posted January 21, 2008 any help?? Link to comment https://forums.phpfreaks.com/topic/86993-storing-timestamp-and-finding-the-difference/#findComment-444849 Share on other sites More sharing options...
mmarif4u Posted January 21, 2008 Share Posted January 21, 2008 for Current date to store from php: $date=date('Y-m-d H:i:s'); Link to comment https://forums.phpfreaks.com/topic/86993-storing-timestamp-and-finding-the-difference/#findComment-444853 Share on other sites More sharing options...
freebsdntu Posted January 21, 2008 Share Posted January 21, 2008 try NOW() function from mysql Link to comment https://forums.phpfreaks.com/topic/86993-storing-timestamp-and-finding-the-difference/#findComment-444861 Share on other sites More sharing options...
corbin Posted January 21, 2008 Share Posted January 21, 2008 INSERT INTO times (time) VALUES (NOW()); SELECT * FROM times WHERE time < NOW() - 600; Link to comment https://forums.phpfreaks.com/topic/86993-storing-timestamp-and-finding-the-difference/#findComment-444863 Share on other sites More sharing options...
mmarif4u Posted January 21, 2008 Share Posted January 21, 2008 for Diff: $date=Retrieve from db; $thendate = strtotime($date); OR $thendate=date('d m Y H:i:s',strtotime($date)); $nowdate = date('d m Y H:i:s'); $datediff = ($nowdate - $thendate); echo $datediff." Seconds<br>"; echo round($datediff / 60)." Minutes<br>"; echo round($datediff / 3600)." Hours<br>"; echo round($datediff / 86400)." Days<br>"; Link to comment https://forums.phpfreaks.com/topic/86993-storing-timestamp-and-finding-the-difference/#findComment-444864 Share on other sites More sharing options...
corbin Posted January 21, 2008 Share Posted January 21, 2008 $nowdate = date('d m Y H:i:s'); $datediff = ($nowdate - $thendate); Errrr...... You're subtracting from a string? Link to comment https://forums.phpfreaks.com/topic/86993-storing-timestamp-and-finding-the-difference/#findComment-444873 Share on other sites More sharing options...
mmarif4u Posted January 21, 2008 Share Posted January 21, 2008 Oh sorry: That would be like this <?php $nowdate = strtotime("20 January 2008"); $thendate = strtotime("4 March 2007"); $datediff = ($nowdate - $thendate); echo $datediff." Seconds<br>"; echo round($datediff / 60)." Minutes<br>"; echo round($datediff / 3600)." Hours<br>"; echo round($datediff / 86400)." Days<br>"; ?> Works fine. Link to comment https://forums.phpfreaks.com/topic/86993-storing-timestamp-and-finding-the-difference/#findComment-444880 Share on other sites More sharing options...
prakash Posted January 21, 2008 Author Share Posted January 21, 2008 I found this one: <?php function timeDiff($firstTime,$lastTime) { // convert to unix timestamps $firstTime=strtotime($firstTime); $lastTime=strtotime($lastTime); // perform subtraction to get the difference (in seconds) between times $timeDiff=$lastTime-$firstTime; // return the difference return $timeDiff; } //Usage: echo timeDiff("2002-03-16 18:56:32","2002-04-16 10:00:00"); ?> Link to comment https://forums.phpfreaks.com/topic/86993-storing-timestamp-and-finding-the-difference/#findComment-444883 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.