我想生成2个DATETIME,代表从星期日到星期六2x开始的最近2周,它不应包括当前不完整的一周。
感谢您的帮助。
答案 0 :(得分:4)
使用精彩的DateTime
类:
<?php
$end = new DateTime('last Sunday'); // note that the end date is excluded from a DatePeriod
$start = clone $end;
$start->sub(new DateInterval('P14D'));
foreach (new DatePeriod($start, new DateInterval('P1D'), $end) as $day) {
echo $day->format('r'), "\n";
}
答案 1 :(得分:3)
开头的事情:
$timestamp_end = strtotime("last Saturday");
$timestamp_start = $timestamp_end - 14 * 24 * 3600;
答案 2 :(得分:0)
<?php
$lastSaturday = strtotime("last Saturday");
//$firstSunday = $lastSaturday - (13 * 24 * 3600);
for($n=13;$n>=0;$n--){
$timeArray[] = $lastSaturday - ($n * 24 * 3600);
$dateTime[] = date('Y-m-d H:i l', $lastSaturday - ($n * 24 * 3600));
}
?>
<pre>
<?php
print_r($dateTime);
?>
</pre>