The date_diff() function returns the difference between two DateTime objects.
PHP date_diff() Function has the following syntax.
date_diff(datetime1,datetime2,absolute);
Parameter | Is Required | Description |
---|---|---|
datetime1 | Required. | DateTime object |
datetime2 | Required. | DateTime object |
absolute | Optional. | TRUE indicates that the interval/difference MUST be positive. Default is FALSE |
PHP date_diff() Function returns a DateInterval object on success that represents the difference between the two dates.
PHP date_diff() Function returns FALSE on failure.
Calculate the difference between two dates
<?php
$date1=date_create("2011-03-15");
$date2=date_create("2013-12-12");
$diff=date_diff($date1,$date2);
?>