Step 1 - PHP date difference
PHP date difference
If you want to get the difference between to dates or time values, then you first need to get the values in the same format. The best way is to convert both dates into Unix timestamp format. In this case the date and time information is stored as an integer so we can calculate the difference easily. You can get the Unix timestamp in various ways as you can see below:Code:
// Get current time // Get the timestamp of 2006 October 20 ?>
Code:
$dateDiff = $date1 - $date2; echo "Differernce is $fullDays days"; ?>
As next step we need to get how many hours are still present in the remaining seconds. So from the original difference we need to remove the complete days in seconds and from the remaining value we can calculate the full hours similar to as we calculated the full days. Repeating these steps for minutes as well at the end we get the difference between the original dates. The complete calculation looks like this:
Code:
$dateDiff = $date1 - $date2; echo "Differernce is $fullDays days, $fullHours hours and $fullMinutes minutes."; ?>