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条)

报告相同问题?

悬赏问题

  • ¥15 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理