Calculate the difference between two dates:
<?php$date1=date_create("2013-03-15");$date2=date_create("2013-12-12");$diff=date_diff($date1,$date2);?>The date_diff() function returns the difference between two DateTime objects.
date_diff( datetime1,datetime2,absolute);
parameter | describe |
---|---|
datetime1 | Required. Specifies a DateTime object. |
datetime2 | Required. Specifies a DateTime object. |
absolute | Optional. Specifies a boolean value. TRUE means the interval/difference must be positive. The default is FALSE. |
Return value: | If successful, a DateInterval object is returned, representing the difference between the two dates. Returns FALSE on failure. |
---|---|
PHP version: | 5.3+ |