PHP date_diff () function
PHP Date / Time Reference Manual
Examples
Calculating the difference between two dates:
<?php
$date1=date_create("2013-03-15");
$date2=date_create("2013-12-12");
$diff=date_diff($date1,$date2);
?>
$date1=date_create("2013-03-15");
$date2=date_create("2013-12-12");
$diff=date_diff($date1,$date2);
?>
Running instance »
Definition and Usage
date_diff () function returns the difference between two DateTime objects.
grammar
date_diff( datetime1,datetime2,absolute);
参数 | 描述 |
---|---|
datetime1 | 必需。规定一个 DateTime 对象。 |
datetime2 | 必需。规定一个 DateTime 对象。 |
absolute | 可选。规定一个布尔值。TRUE 表示间隔/差值必须是正的。默认是 FALSE。 |
technical details
return value: | If successful, it returns a DateInterval object that represents the difference between the two dates. If it fails it returns FALSE. |
---|---|
PHP version: | 5.3+ |
PHP Date / Time Reference Manual