dongzhou4727 2012-08-30 10:35
浏览 129
已采纳

检查当前日期是否在假期日期范围内

How to check if current date falls in holiday date range? I have a table "holidays" with two DATE columns, start_date and end_date. Users can define holidays dates in that range. I need to make a loop that checks is the current date within the holiday date range, and if it is, the current date goes "+1 day", and checks again. I've made it so far:

<?php
include ("config.php");
$curdate = date('Y-m-d', time());
$res = mysql_query("SELECT * FROM holidays WHERE '$curdate' BETWEEN `start_date` and `end_date`");
$resu = mysql_num_rows($res);
 if ($resu == NULL)
      {
      echo "Date is not range";
      }
 else
    {
    echo "Date is in range";
    }
?>
  • 写回答

4条回答 默认 最新

  • duanchazhou6779 2012-08-30 10:53
    关注

    You don't need to have a loop, so you can do it like this

    <?php
       include ("config.php");
       $curdate = date('Y-m-d', time());
       $res = mysql_query("SELECT id FROM holidays WHERE '$curdate' BETWEEN `start_date` and `end_date`");
       $resu = mysql_num_rows($res);
       if ($resu == 0)
       {
          echo "Date is not range";
       }
       else
       {
          $res = mysql_query("SELECT end_date FROM holidays WHERE end_date > '$curdate' ORDER BY end_date ASC LIMIT 1");
          $resu = mysql_fetch_array($res);
    
          $next_day = strtotime($resu['end_date']) + 24 * 60 * 60;
          echo 'The next available day is ' . date("Y-m-d", $next_day);
       }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 为什么我写出来的绘图程序是这样的,有没有lao哥改一下
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号