date_diff


 

date_diff

This is the example of finding the date difference in PHP.

This is the example of finding the date difference in PHP.

date_diff

date_diff alias DateTime::diff returns the difference between two DateTime objects. It returns the difference of two dates, if it exists or return zero.

Description

public DateInterval DateTime::diff ( DateTime $datetime [, bool $absolute ] )

Parameters

datetime - The date to compare to.

absolute - Whether to return absolute difference. Defaults to FALSE.

Example:

<?php
$start = new DateTime('08-24-2009 India/Kolkata'); // DD-MM-YYYY
$end = new DateTime('07-15-1998 UAE/Dubai');

if ($start < $end) {
echo "Correct order";
} else {
echo "Incorrect order, end date is before the starting date";
}
?>

Ads