【问题标题】:Php check if my date from db is today echo with today and if tomorrow then echo tomorrowPHP检查我从db的日期是否是今天与今天相呼应,如果明天则与明天相呼应
【发布时间】:2017-11-15 07:53:55
【问题描述】:

如何检查我的数据库中的日期时间是否是今天,然后回显“今天”,如果我的日期时间是明天回显明天。我想做这个作为全日历的日期提醒。

我的 PHP 代码不工作或乱码:

$reminder = date('d-M-Y',strtotime(date("d-m-Y", strtotime($row['start'])) . " +0 days"));
$tomorrow = strtotime("+1 day");
$tomorrow = getdate($tomorrow);

if($reminder = "0 Days") {
    echo "Today";
} else if($reminder = "1 Days" ) {
    echo "Tomorrow";
} else {
    echo (strtotime($reminder) - strtotime(date('d-M-Y'))) / (60 * 60 * 24).' Days';
}

【问题讨论】:

标签: php


【解决方案1】:
<?php

$date='14-Nov-2017';
$time = strtotime($date);
$formatDate = date('Y-m-d',$time);
echo $formatDate;
$today=date("Y-m-d");

if($formatDate==date("Y-m-d")){
    echo "TODAY";
}
else if ($formatDate==date('Y-m-d', strtotime($today. ' +1 days'))){
    echo 'TOMORROW';
}
else{
    echo "Another day";
}

此代码获取您输出的日期,并将其与今天的日期、明天的日期进行比较,否则只会回显另一个日期。经过测试,它也可以工作。

【讨论】:

    【解决方案2】:

    你可以这样试试:

    $diff = date_diff(date('d-M-Y'), date('d-M-Y', strtotime($row['start'])));
    
    if($diff == 0) {
        echo "Today";
    } else if($diff == 1) {
        echo "Tomorrow";
    }
    

    【讨论】:

      【解决方案3】:

      检查你的 if 语句,你是在设置而不是检查。

      在您的ifs 中将您的= 替换为==

      if($reminder == "0 Days") {
          echo "Today";
      } else if($reminder == "1 Days" ) {
          echo "Tomorrow";
      } else {
          echo (strtotime($reminder) - strtotime(date('d-M-Y'))) / (60 * 60 * 24).' Days';
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-10-26
        • 2021-11-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-22
        • 2011-05-02
        • 2017-01-13
        相关资源
        最近更新 更多