dongman5539 2015-01-29 12:59
浏览 44
已采纳

如何在php中将日期时间的第一个对象与另一个日期时间对象进行比较

here I am using one date time object is this

 $cdate  = date('d/m/Y h:i:sa')  

and another date time object is this

$udate = date("d/m/Y h:i:sa", strtotime("72 hours"));

for comparing I am using this condition

 if($cdate >= $udate)

but problem is this...in this case its only comparing only day not entire date and time.

  • 写回答

5条回答 默认 最新

  • douzhuoxia0587 2015-01-29 13:02
    关注

    The strings returned from date() are only comparable in certain circumstances. You should use DateTime() whose objects are always comparable:

    $cdate  = new DateTime();
    $udate = new DateTime('+3 days');
    if($cdate >= $udate) {
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 vhdl+MODELSIM
  • ¥20 simulink中怎么使用solve函数?
  • ¥30 dspbuilder中使用signalcompiler时报错Error during compilation: Fitter failed,求解决办法
  • ¥15 gwas 分析-数据质控之过滤稀有突变中出现的问题
  • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
  • ¥15 知识蒸馏实战博客问题
  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题