Share on Google+Share on Google+

date_diff

Advertisement
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

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.