I got two timestamps:
$date1 = new DateTime("2017-08-02T08:00:00.000Z");
$date2 = new DateTime("2017-10-02T17:00:00.000Z");
I need to know how many hours were between those two, between 08:00 to 17:00.
It should return 24h, 3 full work days.
I got two timestamps:
$date1 = new DateTime("2017-08-02T08:00:00.000Z");
$date2 = new DateTime("2017-10-02T17:00:00.000Z");
I need to know how many hours were between those two, between 08:00 to 17:00.
It should return 24h, 3 full work days.
<?php
$date1 = new DateTime("2017-08-02T10:19:55.022Z");
$date2 = new DateTime("2017-10-02T10:19:55.022Z");
$interval = $date1 ->diff($date2 );
echo $interval->format('%h')." Hours ".$interval->format('%i')." Minutes";
?>
Get the interval of these two dates;
$date1 = new DateTime("2017-08-02T10:19:55.022Z");
$date2 = new DateTime("2017-10-02T10:19:55.022Z");
$diff = $date1 ->diff($date2);
$diff
is an instance of DateInterval Like below:
DateInterval {#727
+"y": 0,
+"m": 2,
+"d": 0,
+"h": 0,
+"i": 0,
+"s": 0,
+"weekday": 0,
+"weekday_behavior": 0,
+"first_last_day_of": 0,
+"invert": 0,
+"days": 61,
+"special_type": 0,
+"special_amount": 0,
+"have_weekday_relative": 0,
+"have_special_relative": 0,
}
So, $diff->d
is the part of day interval $diff->h
is the part of hour interval. You can use these properties to get what you want.
More details of class DateInterval, please checkout this official documentation: http://php.net/manual/en/class.dateinterval.php
<?php
$date1 = new DateTime("2017-08-02T10:19:55.022Z");
$date2 = new DateTime("2017-10-02T10:19:55.022Z");
$interval = $date1->getTimestamp() -$date2->getTimestamp();
echo abs($interval/(60*60));
?>