Home>Article>Backend Development> Definition and usage of php date_diff function

Definition and usage of php date_diff function

巴扎黑
巴扎黑 Original
2017-05-24 14:28:50 5251browse

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:

   format("%R%a days"); ?>  

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn