PHP date_diff()関数
例
2つの日付の差を計算します。
<?php
$date1=date_create("2013-03-15");
$date2=date_create("2013-12-12");
$diff=date_diff($date1,$date2);
?>
定義と使用法
date_diff()関数は、2つのDateTimeオブジェクト間の差を返します。
構文
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 |
技術的な詳細
戻り値: | 2つの日付の差を表すDateIntervalオブジェクトを成功時に返します。失敗するとFALSE |
---|---|
PHPバージョン: | 5.3+ |
❮PHPの日付/時刻リファレンス