tiota Posted July 6, 2010 Share Posted July 6, 2010 How to calculate the time difference, in my database there were two fields namely timein and timeout. Let's say timein = "08:00:00" and timeout = "04:00:00" on the same day when i did the substraction between timein and timeout it returns 4 hrs which is wrong . it should returns 8 hrs as i expected. I've search on the net and had not found a good guide/solution to my problems Quote Link to comment https://forums.phpfreaks.com/topic/206926-calculate-time-difference/ Share on other sites More sharing options...
harristweed Posted July 6, 2010 Share Posted July 6, 2010 http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_timediff Quote Link to comment https://forums.phpfreaks.com/topic/206926-calculate-time-difference/#findComment-1082099 Share on other sites More sharing options...
Pikachu2000 Posted July 6, 2010 Share Posted July 6, 2010 Actually, that calculated correctly. The item went in at 0400 and went out at 0800. Or did you mean the item went out at 0800 and in at 1600? Quote Link to comment https://forums.phpfreaks.com/topic/206926-calculate-time-difference/#findComment-1082140 Share on other sites More sharing options...
myrddinwylt Posted July 6, 2010 Share Posted July 6, 2010 You could also modify the way the timestamp is formatted. From what it looks like, it is in 24 hour format, in which case 04:00 is 4am, and 08:00 is 8am. Switch the format to use either of the following formats 04:00:00 PM / 08:00:00 AM h:i:s A OR 16:00:00 / 08:00:00 H:i:s When formatting date/time in PHP, the characters used are case sensitive. Hours, Minutes, and Seconds, in 12 hour format without AM/PM are meaningless, especially when doing calculations. In 24 hour format, the math and appearance is much cleaner, and simpler. Quote Link to comment https://forums.phpfreaks.com/topic/206926-calculate-time-difference/#findComment-1082175 Share on other sites More sharing options...
tiota Posted July 12, 2010 Author Share Posted July 12, 2010 Thank you very much for help Quote Link to comment https://forums.phpfreaks.com/topic/206926-calculate-time-difference/#findComment-1084730 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.