mktime函数:根据给定时间计算距1970-1-1的秒数。
<?php
$date_from=mktime(0,0,0,11,17,2004);
$date_to=mktime(0,0,0,11,18,2004);
$temp=($date_to-$date_from)/86400;
if($temp>=1 and $temp<2) echo '大于一天';
if($temp>=2 and $temp<3) echo '大于二天';
if($temp>=3 and $temp<4) echo '大于三天';
?>

解决方案 »

  1.   

    注:mktime函数:根据给定时间计算距1970-1-1的秒数。
    <?php
    $date_from=mktime(0,0,0,11,17,2004);       //2004-11-17 00:00:00
    $date_to=mktime(0,0,0,11,18,2004);         //2004-11-18 00:00:00
    $temp=($date_to-$date_from)/86400;         //一天等于86400秒
    if($temp>=1 and $temp<2) echo '大于一天';
    if($temp>=2 and $temp<3) echo '大于二天';
    if($temp>=3 and $temp<4) echo '大于三天';
    ?>
      

  2.   

    谢谢 jxflll(峰) ,我试一下,因为初学可能比较慢,还请多指点。
      

  3.   

    datediff(d,a.MON,'$DateTime')>1   //MON-$DateTime>1天
    datediff(d,a.MON,'$DateTime')>2
      

  4.   

    http://www.phpe.net/faq/65.shtml;
      

  5.   

    谢谢jxflll(峰) 和 danis_cn(宇宙鸟) 和  spacet(空格t) 
    峰的答案应该比较正确,宇宙鸟的答案中是否有datediff函数,我查不到,是否为javascript的
    空格的文章看过了,因为是初学所以看不大懂我现在有一日期格式为字符串:2004-12-02 08:18:12  和 2004-12-08 09:18:12
    要计算两个字符时间的差是否为一天,二天,大于等于三天结果。不知字符如何转换。
    谢谢各位了。
      

  6.   

    <?
    $d1 = '2004-12-02 08:18:12';
    $d2 = '2004-12-08 09:18:12';$dt = 24*60*60;echo $t = (strtotime($d2) - strtotime($d1))/$dt;
    ?>
      

  7.   

    $date = "2004-12-02 08:18:12";
    $date1 = "2004-12-08 09:18:12";
    echo strtotime($date)."<br>";
    echo strtotime($date1)."<br>";
    $date2 = strtotime($date1)-strtotime($date);
    echo $date2;
    这样得到的$date2就是相差的秒数,再除以3600就是小时了