juanc Posted March 1, 2006 Share Posted March 1, 2006 Hi can someone help me please, My goal is to add to different times into two different mySQL columns (in the same row and inputted one after the other) then calculate the number of minutes in between each.For each column I input using strftime('%H %M', time())Then I used this function to calculate the difference[code]function DateDiff($interval,$date1,$date2) { // get the number of seconds between the two dates $timedifference = $date2 - $date1; switch ($interval) { case 'w': $retval = bcdiv($timedifference,604800); break; case 'd': $retval = bcdiv($timedifference,86400); break; case 'h': $retval =bcdiv($timedifference,3600); break; case 'n': $retval = bcdiv($timedifference,60); break; case 's': $retval = $timedifference; break; } return $retval;}[/code]Then I did [code]echo DateDiff('n',$row[start],$row[end]);[/code]but it just gives back 0 .............at the same time I'll add that the mysql columns I originally had as varchar then changed them to timehope someone can help Quote Link to comment Share on other sites More sharing options...
XenoPhage Posted March 1, 2006 Share Posted March 1, 2006 Why not use the mysql date functions? DATE_ADD and DATE_SUB ?[a href=\"http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html\" target=\"_blank\"]http://dev.mysql.com/doc/refman/5.0/en/dat...-functions.html[/a] Quote Link to comment 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.