user image

Yasen Sayed
Published in : 2022-02-25

php difference between two times in hours

PHP & Mysql

Hello guys, anyone can help me to get the difference between the two times in PHP for example:

 "from" => "12:00:00"
 "to" => "20:00:00"

I want the difference between these times in hours.

 

Thanks.

Comments

Rakshit Date : 2022-02-25

Best answers

34

Best answers

34

If you are using 24 hours format you don't need AM or PM annotations at all.

 

By default 00:00:00 means 12:00 AM of the day. 

In the given example, from timestamp shows time = 12:00:00, it means 12 hours passed, so your time is - 12:00 PM of the day.

 

To timestamp shows 20:00:00, it means 8:00 PM of the respective day. Max time can be 23:59:59, and after that it will be turned to 00:00:00 (12:00 AM)

 

You can add number of hours in 12:00:00 PM to count further all hours in 24 hours format if you see the time > 12:00:00.

 

Shilpa Date : 2022-02-26

Best answers

10

Best answers

10

It shows you are using 24 hours format.

From date shows 12 O'clock of Afternoon

To date shows 8 O'clock of evening!

Leave a comment

Join us

Join our community and get the chance to solve your code issues & share your opinion with us

Sign up Now

Related posts

MySQL - Lost connection to MySQL server during query - Required a solution.
Publish date: 2022-03-03 | Comments: 1

Tag: PHP & Mysql

mysql service start not exist
Publish date: 2022-02-23 | Comments: 4

Tag: PHP & Mysql

Mysql query: How do I count the day streak of particular user?
Publish date: 2022-03-01 | Comments: 4

Tag: PHP & Mysql

PHP mail function goes to spam not inbox
Publish date: 2022-02-28 | Comments: 2

Tag: PHP & Mysql

[solved] Storage engine 'InnoDB' does not support system tables
Publish date: 2022-01-09 | Comments: 0

Tag: PHP & Mysql

ERROR 1410 (42000): You are not allowed to create a user with GRANT
Publish date: 2022-04-01 | Comments: 2

Tag: PHP & Mysql

[solved] #1273 - Unknown collation: 'utf8mb4_0900_ai_ci'
Publish date: 2022-01-09 | Comments: 1

Tag: PHP & Mysql

change user root privelige and password
Publish date: 2022-02-23 | Comments: 1

Tag: PHP & Mysql