PHP date_diff() Function
Definition
The date_diff() function returns the difference between two DateTime objects.
Syntax
PHP date_diff() Function has the following syntax.
date_diff(datetime1,datetime2,absolute);
Parameter
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 |
Return
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.
Example
Calculate the difference between two dates
<?php/* w w w . jav a 2s. c om*/
$date1=date_create("2011-03-15");
$date2=date_create("2013-12-12");
$diff=date_diff($date1,$date2);
?>