给定的具体日期仅在今天返回



我正在使用日历重复/重复事件-最佳存储方法上的此代码

有人能帮我从指定的日期开始运行脚本吗?剧本写得很好,但总是从今天开始。

我想更改:$now=strtotime("今天"(;到$now=strtotime("2021-04-01"(;

//    $now = strtotime("today");
//$now = date( "Y-m-d", strtotime( "2009-01-31" ));
//$now = date("Y-m-d", strtotime("2014-12-31") );
//$now = "2013-04-11";
//$now = date("Y-m-d", strtotime("2015-04-01"))."n";
//$now = strtotime('2007-12-21');
$now = strtotime('11-11-2007');
$pushToFirst = 0;
for($i = $pushToFirst; $i < $pushToFirst+3; $i++)
{
$now = strtotime("+".$i." day");
//$now = date("+".$i." day");
$year = date("Y", $now);
$month = date("m", $now);
$day = date("d", $now);
$nowString = $year . "-" . $month . "-" . $day;
$week = (int) ((date('d', $now) - 1) / 7) + 1;
$weekday = date("N", $now);
echo $nowString . "<br />";
echo $week . " " . $weekday . "<br />";
$sql = "SELECT EV.*
FROM `planering1` EV
RIGHT JOIN `planering_namn` PN1 ON PN1.`NAMN` = EV.`namn`
RIGHT JOIN `planering_meta` EM1 ON EM1.`event_id` = EV.`ID`
WHERE ( DATEDIFF( '$nowString', repeat_start ) % repeat_interval = 0 )
OR ( 
(repeat_year = $year OR repeat_year = '*' )
AND
(repeat_month = $month OR repeat_month = '*' )
AND
(repeat_day = $day OR repeat_day = '*' )
AND
(repeat_week = $week OR repeat_week = '*' )
AND
(repeat_weekday = $weekday OR repeat_weekday = '*' )
AND repeat_start <= DATE('$nowString')
)";
foreach ($dbConnect->query($sql) as $row) {
print $row['namn'] . "t";
print $row['tur'] . "<br />";
}
echo "<br /><br /><br />";
}

我会考虑更改代码的这一部分

// $now = strtotime('11-11-2007'); // remove this line
$start = strtotime('2021-04-01'); // the date you want to start with
$pushToFirst = 0;
for($i = $pushToFirst; $i < $pushToFirst+3; $i++)
{
//        $now = strtotime("+".$i." day"); // remove this line
// there are 86400 secs in a day, this will increase the day based on the start date, rather then just taking +$i days from now
$now = $start + ($i * 86400); 

编辑

strtotime假设您正在谈论";现在";,作为默认参考点。因此,如果你说strtotime("+1天"(,那将是从现在起1天;如果你说trtotime("+5天"(,那就是从现在起5天。

有几种方法可以解决这个问题,

  1. strtotime可以接受2个参数

https://www.php.net/manual/en/function.strtotime.php

strtotime("+1天",$start(将在参考点使用$start。所以$start+1天

  1. $now=$start+($i*86400(;这就是我选择使用的,每天有86400秒,所以我只是在添加以秒为单位的天数

两者都有相同的结果,请使用您更容易阅读的结果。

相关内容

  • 没有找到相关文章

最新更新