【发布时间】:2014-01-13 06:38:52
【问题描述】:
我正在使用我的代码生成日期,我想排除周日和周六,请在此处查看我的代码
for ($date = $start_date; $date <= $end_date; $date = date('Y-m-d', strtotime($date . ' + 1 day'))) {
$week = date('W', strtotime($date));
$year = date('Y', strtotime($date));
$from = date("Y-m-d", strtotime("$date"));
if ($from < $start_date)
$from = $start_date;
$to = date("Y-m-d", strtotime("$date-1day + 1 week"));
if ($to > $end_date) {
$to = $end_date;
}
if ($from <= $to) {
array_push($weekfrom, $from);
array_push($weekto, $to);
}
$n = count($weekfrom);
for ($i = 0; $i < $n; $i++) {
echo $weekfrom[$i];
}}
【问题讨论】:
-
缺少右括号
-
哎呀抱歉我忘了 :) 已经编辑了 :) 谢谢
-
我不明白这一行:
$to = date("Y-m-d", strtotime("$date-1day + 1 week")); //Returns the date of sunday in week。对我来说,你只是加了 6 天,它怎么变成了一个星期天? -
抱歉这里的评论 :) 我的代码中有错误的评论
-
我会使用
DateTime和DatePeriod中的对象,例如this answer 这个问题也是this question 的重复问题。