未定义的date_diff() [英] Undefined date_diff()

查看:97
本文介绍了未定义的date_diff()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 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');

它对我不起作用,出现错误:

Its doesn't work for me, gives an error:

Call to undefined function  date_diff()

如何使它工作?

使用了PHP 5.2。

PHP 5.2 is used.

谢谢。

推荐答案

函数date_diff需要5.3或更高版本的PHP。

The function date_diff requires a PHP version of 5.3 or greater.

更新

PHP 5.2的示例(摘自date_diff用户注释)。

An example for PHP 5.2 (taken from the date_diff user comments).

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

这篇关于未定义的date_diff()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆