$t1=time();
$t2=time();
$t3=$t2-$t1;
$d1=date("U");
$d2=date("U");
$d3=$d2-$d1;

解决方案 »

  1.   

    <?php

    // +----------------------------------------------------------------------+
    // | PHP version 4.0                                                      |
    // +----------------------------------------------------------------------+
    // | Copyright (c)  2003 The individual                                   |
    // +----------------------------------------------------------------------+
    // |It agrees without being passing through the very person and it is     |
    // |conceited secretly using the after result.                            |
    // +----------------------------------------------------------------------+
    // | Authors: Original Author  Allan Kent                                 |
    // |          Editing          Dandelion                                  |
    // +----------------------------------------------------------------------+

    /** 
    * @Purpose: 
    * It returns to the time interval during two dates.
    * @Method Name: DateDiff().
    * @Parameter: string $interval -->The time interval character string numerical   formula.
    *                                  w -->Weekday
    *                                  d -->Day
    *                                  h -->Hour
    *                                  n -->Minute
    *                                  s -->Second
    *           string $date1    -->It represents as time() a form in the time of the first date.
    *           string $date2    -->It represents as time() a form in the time of the second date.
    * @Return: string $retval   -->Return a new as time() a form in the time of the date.
    * @See: string bcdiv(string left operand,string right operand, int [scale]).
    */ function DateDiff($interval, $date1, $date2) { 
        
        // @See: It gets the number of the seconds in the one of the 2nd period day interval.
        $time_difference = $date2 - $date1; 
        switch ($interval) {
         
            case "w": $retval = bcdiv($time_difference, 604800); break; 
            case "d": $retval = bcdiv($time_difference, 86400);  break; 
            case "h": $retval = bcdiv($time_difference, 3600);   break; 
            case "n": $retval = bcdiv($time_difference, 60);     break; 
            case "s": $retval = $time_difference;                break; 
        } 
        
        return $retval;} ?>
      

  2.   

    首先把两个时间都用mktime化成时间戳,然后把两个时间戳相减,除以86400就是相隔的天数
      

  3.   

    mktime(03 12 2003 8:49AM)mktime(2003-3-12 8:10:00)这两个时间可以求差吗
    在线等
      

  4.   

    用 mktime 不合适,不如用 strtotime strtotime("03 12 2003 8:49AM")
    strtotime("2003-3-12 8:10:00")
      

  5.   

    因为03 12 2003 9:04AM 不是有效的日期格式
    echo (strtotime("2003-03-12 9:05:36")-strtotime("03/12/2003 9:04AM"))/3600; // out 0.026666666666667
      

  6.   

    我的数据库为sql2000表里时间字段的值为 2003-03-12 9:05:36这种格式。但我从数据库中读出来就变成03 12 2003 9:04AM这种格式,我运行环境是php4.3.0+win2000p 读数据库的函数是$rows=mssql_fetch_row($query);
    请指点
    在线等
      

  7.   

    1、读出是可以做格式变换
    2、做日期比较可在sql里进行,不必取出来再做。DateDiff是mssql的函数,Successful(火烈鸟) 给出的是php的仿DateDiff函数,其实mysql有自己的日期时间函数
      

  8.   

    用mktime获得两个时间的秒数然后对比。