sun14php Posted June 29, 2006 Share Posted June 29, 2006 i am using two time colums to store 2 time values using currtime() mysql function.now i want to store the diff. between above two time filed into [b]minutes[/b] in a another field likePASTTIME NOWTIMKE DIFFRENCE05:10:00 05:20:00 10how can i achive above resultguide me please. Link to comment https://forums.phpfreaks.com/topic/13203-time-diff-in-minutes/ Share on other sites More sharing options...
obsidian Posted June 29, 2006 Share Posted June 29, 2006 [!--quoteo(post=389233:date=Jun 29 2006, 08:47 AM:name=sun14php)--][div class=\'quotetop\']QUOTE(sun14php @ Jun 29 2006, 08:47 AM) [snapback]389233[/snapback][/div][div class=\'quotemain\'][!--quotec--]i am using two time colums to store 2 time values using currtime() mysql function.now i want to store the diff. between above two time filed into [b]minutes[/b] in a another field likePASTTIME NOWTIMKE DIFFRENCE05:10:00 05:20:00 10how can i achive above resultguide me please.[/quote]i would run something like this:[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']UPDATE[/span] tableName SET diffrence [color=orange]=[/color] MINUTE(TIMEDIFF(PASTTIME, NOWTIMKE)); [!--sql2--][/div][!--sql3--]obviously, this will set ALL your rows, so you could add a WHERE clause that would update only one row of your choice.also, keep in mind that the mysql function MINUTE() will only return an int between 0 and 59, so if you are ever going to have a difference of more than an hour, you may want to rethink how you handle them. Link to comment https://forums.phpfreaks.com/topic/13203-time-diff-in-minutes/#findComment-50804 Share on other sites More sharing options...
hvle Posted June 29, 2006 Share Posted June 29, 2006 you can explode the time into hours/min/sec like this$time1 = '05:10:00';$time2 = '05:20:00';$starttime = explode(':', $time1);$endtime = explode(':', $time2);$difference = ($endtime[0] - $starttime[0]) * 60 + ($endtime[1] - $starttime[1]);echo $difference;Did you consider the case that the result maybe wrong if the 2 time was taken more than 24 hours apart? Link to comment https://forums.phpfreaks.com/topic/13203-time-diff-in-minutes/#findComment-50805 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.