dongshan2680 2017-06-04 02:11
浏览 27

在PHP中使用if条件中的日期?

I make a condition like this

<?php $todays_date = date("d F Y"); ?> //echo 04 June 2017
<?php $deadline_date = date("d F Y",strtotime($tugas->deadline_tugas));?> //echo 25 May 2017
<?php if ($todays_date < $deadline_date){  <--- I confused in this condition!
 echo "<a class='btn btn-primary btn-lg btn-block' href=\"student_tugas/".$tugas->id_tgs."\">Go Activate!</a>";
 }else {
    echo "<button type='button' class='btn btn-primary btn-lg btn-block' disabled='disabled'>Oops!</button>";
} ?>

I want this code run when $deadline_date has reached $todays_date and so then the button is "Oops!" but when the $deadline_date has reached $todays_date yet then the button will be show "Go Activate!". As long as $deadline_date has not reach $todays_date and so the button "Go Activate!" will be show.

Could you help me?

  • 写回答

1条回答 默认 最新

  • douyi1982 2017-06-04 03:02
    关注

    your if statement is compare 2 string come from the date() function. So it will now be correctly, for example 'June' < 'May', but actually not.

    Refer to this post for compare the date and the manual of date()

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看