SirChick Posted October 30, 2007 Share Posted October 30, 2007 How do you do a time comparison against a time stamp in the database: $Started = ['Started']; And a time representing now : $Date = date("Y-m-d H:i:s",time()); But i wanted the difference from now to the start to be given back in minutes only..how is this done? Quote Link to comment https://forums.phpfreaks.com/topic/75374-solved-time-comparison-against-minutes/ Share on other sites More sharing options...
GingerRobot Posted October 30, 2007 Share Posted October 30, 2007 You can do it all with mysql functions: SELECT TIME_FORMAT( TIMEDIFF( NOW( ) , `yourfield` ) , '%i' ) AS difference FROM `yourtable` This will return the number of whole minutes between your timestamp and the current time. Quote Link to comment https://forums.phpfreaks.com/topic/75374-solved-time-comparison-against-minutes/#findComment-381261 Share on other sites More sharing options...
SirChick Posted October 30, 2007 Author Share Posted October 30, 2007 %i whats that bit do ^? Quote Link to comment https://forums.phpfreaks.com/topic/75374-solved-time-comparison-against-minutes/#findComment-381296 Share on other sites More sharing options...
GingerRobot Posted October 30, 2007 Share Posted October 30, 2007 Its the format string for minutes. See: http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format Quote Link to comment https://forums.phpfreaks.com/topic/75374-solved-time-comparison-against-minutes/#findComment-381308 Share on other sites More sharing options...
SirChick Posted October 30, 2007 Author Share Posted October 30, 2007 How do you then just put the result into $Difference ? Quote Link to comment https://forums.phpfreaks.com/topic/75374-solved-time-comparison-against-minutes/#findComment-381365 Share on other sites More sharing options...
GingerRobot Posted October 30, 2007 Share Posted October 30, 2007 <?php $sql = "SELECT TIME_FORMAT( TIMEDIFF( NOW( ) , `yourfield` ) , '%i' ) AS difference FROM `yourtable`"; $result = mysql_query($sql)or die(mysql_error()); $difference = mysql_result($result,0); // or ,if you are selecting other fields as well: $difference = mysql_result($result,0,'difference'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/75374-solved-time-comparison-against-minutes/#findComment-381415 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.