date_diff

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

 
 

Share on Google+Share on Google+

date_diff

Ads

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";
}
?>

Advertisements

Posted on: August 25, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles