PHP Calculate Time Difference Between Two Dates in Hours Example
In this article we will cover on how to implement php calculate time difference between two dates in hours. you'll learn php difference between two dates in hours. This tutorial will give you simple example of how to calculate time difference between two dates in php. I’m going to show you about how to find difference between two dates in hour in php. You just need to some step to done php calculate time difference between two dates in hours.
Let's see simple example of how to get difference between two dates in hours with php.
Example:
<?php
$date1 = "2021-09-05 01:00:00";
$date2 = "2021-09-06 02:00:00";
$timestamp1 = strtotime($date1);
$timestamp2 = strtotime($date2);
$hours = abs($timestamp2 - $timestamp1)/(60*60);
echo "Difference between two dates is " . $hours . " hour(s)";
Output:
Difference between two dates is 25 hour(s)
i hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel Carbon Subtract Days to Date Example
- Angular Change Date Format in Component Example
- How to Get Current Date and Time in AngularJS?
- How to Change Date Format in Codeigniter?
- Bootstrap Timepicker using Datetimepicker JS Example
- Laravel Change Date Format using Carbon Example
- How to Get Hours Difference Between Two Dates in Laravel?
- How to Get Month Difference Between Two Dates in Laravel?
- How to Find Day Name from Specific Date in PHP?
- How to Get Difference Between Two Dates in Laravel?