Cyto Posted June 3, 2012 Share Posted June 3, 2012 Hi, Is it possible to do a calculation by php from this: 00:01:08,035 - 00:02:03,054 = 00:00:55,019 I'm trying to get the duration of a start and end time. Cyto Quote Link to comment https://forums.phpfreaks.com/topic/263558-minus-with-characters/ Share on other sites More sharing options...
requinix Posted June 3, 2012 Share Posted June 3, 2012 Convert the times to seconds, do the math, and convert back. Using addition as a better example, 0 * 3600 + 1 * 60 + 8.035 = 68.035 0 * 3600 + 2 * 60 + 3.054 = 123.054 123.054 + 68.035 = 191.089 191.089 / 3600 = 0 remainder 191.089 191.089 / 60 = 3 remainder 11.089 so 00:01:08,035 + 00:02:03,054 = 00:03:11,089 Quote Link to comment https://forums.phpfreaks.com/topic/263558-minus-with-characters/#findComment-1350701 Share on other sites More sharing options...
Cyto Posted June 3, 2012 Author Share Posted June 3, 2012 Can you give me a example code, cant come out Convert the times to seconds, do the math, and convert back. Using addition as a better example, 0 * 3600 + 1 * 60 + 8.035 = 68.035 0 * 3600 + 2 * 60 + 3.054 = 123.054 123.054 + 68.035 = 191.089 191.089 / 3600 = 0 remainder 191.089 191.089 / 60 = 3 remainder 11.089 so 00:01:08,035 + 00:02:03,054 = 00:03:11,089 Quote Link to comment https://forums.phpfreaks.com/topic/263558-minus-with-characters/#findComment-1350706 Share on other sites More sharing options...
requinix Posted June 3, 2012 Share Posted June 3, 2012 What do you have now? I ask mostly because I don't know what inputs you're starting with. Quote Link to comment https://forums.phpfreaks.com/topic/263558-minus-with-characters/#findComment-1350707 Share on other sites More sharing options...
Cyto Posted June 3, 2012 Author Share Posted June 3, 2012 I'm getting the inputs from a file like above(00:01:08,035) start and end time, so it's hard * no clue* Quote Link to comment https://forums.phpfreaks.com/topic/263558-minus-with-characters/#findComment-1350861 Share on other sites More sharing options...
requinix Posted June 3, 2012 Share Posted June 3, 2012 Give it a shot. Here's something you can use in it: function timediff($start, $end) { sscanf($start, "%d:%d:%d,%d", $shour, $sminute, $ssecond, $sfraction); sscanf($end, "%d:%d:%d,%d", $ehour, $eminute, $esecond, $efraction); Quote Link to comment https://forums.phpfreaks.com/topic/263558-minus-with-characters/#findComment-1350953 Share on other sites More sharing options...
Cyto Posted June 3, 2012 Author Share Posted June 3, 2012 Hi, Thx for your reply. I tried the above code and echoed it, but gives me a empty result. Quote Link to comment https://forums.phpfreaks.com/topic/263558-minus-with-characters/#findComment-1350963 Share on other sites More sharing options...
requinix Posted June 4, 2012 Share Posted June 4, 2012 What's your code? Quote Link to comment https://forums.phpfreaks.com/topic/263558-minus-with-characters/#findComment-1350970 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.