我正在尝试使用date_diff():
$datetime1 = date_create('19.03.2010');
$datetime2 = date_create('22.04.2010');
$interval = date_diff($datetime1, $datetime2);
echo $interval->format('%R%d days');
Run Code Online (Sandbox Code Playgroud)
它不适合我,给出一个错误:
Call to undefined function date_diff()
Run Code Online (Sandbox Code Playgroud)
我怎样才能让它发挥作用?
使用PHP 5.2.
谢谢.
Pet*_*han 12
函数date_diff需要5.3或更高版本的PHP版本.
UPDATE
PHP 5.2的一个示例(取自date_diff用户注释).
<?php
function date_diff($date1, $date2) {
$current = $date1;
$datetime2 = date_create($date2);
$count = 0;
while(date_create($current) < $datetime2){
$current = gmdate("Y-m-d", strtotime("+1 day", strtotime($current)));
$count++;
}
return $count;
}
echo (date_diff('2010-3-9', '2011-4-10')." days <br \>");
?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17123 次 |
| 最近记录: |