THE WORLD'S LARGEST WEB DEVELOPER SITE

PHP date_diff() Function

❮ PHP Date/Time Reference

Example

Calculate the difference between two dates:

<?php
$date1=date_create("2013-03-15");
$date2=date_create("2013-12-12");
$diff=date_diff($date1,$date2);
?>
Run example »

Definition and Usage

The date_diff() function returns the difference between two DateTime objects.


Syntax

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 indicates that the interval/difference MUST be positive. Default is FALSE

Technical Details

Return Value: Returns a DateInterval object on success that represents the difference between the two dates. FALSE on failure
PHP Version: 5.3+

❮ PHP Date/Time Reference