A bit nicer is the following:
$a = new DateTime('08:00'); $b = new DateTime('16:00'); $interval = $a->diff($b); echo $interval->format("%H");
That will give you the difference in hours.
More Related Contents:
- Display which day it is? sunday or monday “php coding”? [closed]
- Check whether the string is a unix timestamp
- php: convert milliseconds to date
- NOW() function in PHP
- Subtracting a certain number of hours, days, months or years from date
- About if else statement [closed]
- How do I compare two DateTime objects in PHP 5.2.8?
- Calculate number of hours between 2 dates in PHP
- Correctly determine if date string is a valid date in that format
- PHP compare time
- Add ‘x’ number of hours to date
- Convert number of minutes into hours & minutes using PHP
- Simplest way to increment a date in PHP?
- Get interval seconds between two datetime in PHP?
- How to store NULL values in datetime fields in MySQL?
- Does UTC observe daylight saving time?
- PHP order array by date? [duplicate]
- Output is in seconds. convert to hh:mm:ss format in php
- How to convert ISO8601 to Date format in php
- How do I find the hour difference between two dates in PHP?
- How to render a DateTime object in a Twig template
- How do I convert datetime to ISO 8601 in PHP
- How do you explain the result for a new \DateTime(‘0000-00-00 00:00:00’)?
- PHP Fatal error: Call to a member function format() on boolean
- PHP script to execute at certain times
- calculate sundays between two dates
- adding 1 day to a DATETIME format value
- day of the week to day number (Monday = 1, Tuesday = 2)
- Convert Time String to Decimal Hours PHP [closed]
- Convert DateTime to String PHP