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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.