我需要按钮添加一周到一周,一个减少

时间:2014-08-26 17:55:37

标签: php date button calendar add

此代码显示周数

<?php 
    $week_number = date("W");
    echo "Week " . $week_number; 
?>

此代码显示该周的日期

<?php
$week_number = date("W");
$year = date("Y");
for($day=1; $day<=7; $day++){
    echo "<td>";
    echo date('d M', strtotime($year."W".$week_number.$day))."\n";
    echo "</td>";
}

它为一周视图日历和我需要的是下一个和上一个按钮跳到下周并回到上周..请帮助我无法找到一个解决方案添加一周或减少一周按钮。

1 个答案:

答案 0 :(得分:1)

$last_week = (new DateTime('last week'))->format('d M');
$next_week = (new DateTime('next week'))->format('d M');

Demo

如果您想从不同的日期开始,代码看起来会有很大的不同:

$date      = $_GET['date']; // Sample value: 2014-08-19
$last_week = (new DateTime($date)->modify('last week'))->format('d M');
$next_week = (new DateTime($date)->modify('next week'))->format('d M');