gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 06:04:31 25 4
gpt4 key购买 nike

如何检查当前日期是否在假期日期范围内?我有一个表“假期”,其中有两个日期列:开始日期和结束日期。用户可以定义该范围内的假期日期。我需要创建一个循环来检查当前日期是否在假日日期范围内,如果是,则当前日期变为“+1 天”,然后再次检查。到目前为止我已经做到了:

<?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";
}
?>

最佳答案

你不需要有一个循环,所以你可以这样做

<?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);
}
?>

关于php - 检查当前日期是否在假期日期范围内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12194934/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com