Definition and usage of php date_diff function

巴扎黑
Release: 2023-03-07 21:32:01
Original
5154 people have browsed it

Definition and usage

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

Syntax

date_diff(datetime1,datetime2,absolute);
Copy after login

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");
?>

Copy after login

Running results:

+272 days
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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 [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!