Jump to content

Calculate time difference


tiota

Recommended Posts

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

 

 

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/206926-calculate-time-difference/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.