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 means the interval/difference must be positive. Default is FALSE.
Return value:
If successful, a DateInterval object is returned, representing the difference between two dates. Returns FALSE on failure.
Example display:
<!DOCTYPE html> <html> <body> <?php $date1=date_create("2013-03-15"); $date2=date_create("2013-12-12"); $diff=date_diff($date1,$date2); echo $diff->format("%R%a days"); ?> </body> </html>
Running results:
+272 days
Set a time 2013-03-15 as $date1, and another time 2013-12-12 as $date2 , and then use the date_diff function to find the difference between the two times and output it.
The above is the detailed content of Definition and usage of php date_diff function. For more information, please follow other related articles on the PHP Chinese website!