Compute 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 interval between two DateTime objects.
date_diff(datetime1, datetime2, absolute) |
Parameter |
Description |
datetime1 |
Required. Specifies a DateTime object. |
datetime2 |
Required. Specifies a DateTime object. |
absolute |
Optional. Specifies a Boolean value. TRUE ensures that the interval/difference is always positive. The default is FALSE. |
Return Value: |
Returns a DateInterval object representing the difference between the two dates on success; FALSE on failure. |
PHP Version: |
5.3+ |