dongmao9217 2012-08-31 11:24 采纳率: 100%
浏览 4
已采纳

比较PHP中的日期和特定日期+时间的返回命令

I'm in the process of making wordpress plugin using PHP. The objective is that the plugin will run until a stated date, than it will stop.

The problem is, let say I stated the expired date is on 16/9/2012. The system will only stop the plugin on 17/9/2012 08:00AM. How can I make it stop at 17/9/2012 12:00AM.

The coding that correspond are shown below. Need your advice. Thanks!

function display($content) {

$exp_date = "16-09-2012";
$todays_date = date("d-m-Y");

$today = strtotime($todays_date);
$expiration_date = strtotime($exp_date);

if ($expiration_date >= $today) {
    return flag().$content;

} else {
        return $content;
    }
}
  • 写回答

2条回答 默认 最新

  • dpnhp20440 2012-08-31 11:41
    关注

    Better to use "mktime()" to make timestamp of expiry date. Then you can compare with current time stamp which you can get by function "time()".

    For example

    $exp_date = mktime(23,59,59,9,16,2012);
    if(time() > $exp_date){
    
     // expired
    
    } else {
    
      // Not expired.
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 php 将rtmp协议转hls协议,无法播放
  • ¥15 miniconda安装不了
  • ¥20 python代码编写
  • ¥20 使用MPI广播数据遇到阻塞
  • ¥15 TinyMCE如何去掉自动弹出的“链接…”工具?
  • ¥15 微信支付转账凭证,如何解决
  • ¥15 在win10下使用指纹登录时,界面上的文字最后一个字产生换行现象
  • ¥20 使用AT89C51微控制器和MAX7219驱动器来实现0到99秒的秒表计数,有开始和暂停以及复位功能,下面有仿真图,请根据仿真图来设计c语言程序
  • ¥15 51单片机 双路ad同步采样
  • ¥15 使用xdocreport 生成word