代码之家  ›  专栏  ›  技术社区  ›  Sam Johannes Rudolph

比较日期(“Y-m-d h:i:s”);

  •  2
  • Sam Johannes Rudolph  · 技术社区  · 14 年前

    我以前用过date(“Y-m-dh:I:s”)&书信电报;日期(“Y-m-d h:i:s”);+但这似乎不起作用。

    救命啊?

    4 回复  |  直到 14 年前
        1
  •  10
  •   Felix Kling    14 年前

    使用 strtotime() 将它们转换为 UNIX time

    例如。:

    if(strtotime($date2) - strtotime($date1) > 30) {
        // $date2 is more than 30 seconds after $date1
    }
    

    if(abs(strtotime($date2) - strtotime($date1)) > 30) {
        // $dates are more than 30 second apart
    }
    
        2
  •  2
  •   bluebrother    14 年前
        3
  •  1
  •   Vladimiroff    14 年前

    改用unixtime。只需转换日期(“Y-m-d h:i:s”);截止日期(“U”)或just time()。 strototime() 我可以帮你。 它以秒为单位显示自Unix纪元(1970年1月1日00:00:00 GMT)以来的时间。那么这个方法$unixtime+30也可以正常工作;)

        4
  •  1
  •   Progman    14 年前

    看起来您正在尝试比较数据库日期字段(如mysql) DATETIME ). 使用数据库系统日期和时间函数来比较日期值(如 DATE_ADD() + 用简单的 < > 在MySQL中)。