建立一个“本周”& “下周”链接查询

时间:2013-09-11 09:01:24

标签: php date calendar

我正在为一个活动网站构建一个脚本,我有快捷链接,用于"今天,7天,14天,30天& 60天,使用PHP从今天开始计算每天工作正常,但我更喜欢将其作为"今天,本周,下周"然后让用户在将来进行任何进一步的自定义搜索。问题是我不知道如何计算这种类型的计算周。例如,我本周可以做到#34;从今天到+ 7"然后在下周做"今天+7到今天+ 14"但这会有点令人困惑,所以我想做的是:

Today = Today //I have the script for this
This Week = Today (Whichever day we are on) to Sunday
Next Week = Next Monday to Next Sunday

任何想法如何做到这一点?

2 个答案:

答案 0 :(得分:1)

date_default_timezone_set(GMT);
$date = date("d/m/Y");// current date
$date = strtotime(date("d/m/Y", strtotime($date)) . " +1 week");

$year = date("Y",$date);
$week = date("W",$date);
echo date('d/m/Y', strtotime($year . 'W' . str_pad($week, 2, '0', STR_PAD_LEFT)));

返回16/09/2013

如果你将+1周改为+2 返回23/09/2013

答案 1 :(得分:0)

echo $today = date("d/m/Y");
echo "<br>";
echo $thisweekends = date("d/m/Y",strtotime("next sunday")); 
echo "<br>";
echo $nextweekstarts = date("d/m/Y",strtotime("next monday"));
echo "<br>";
echo $nextweekends = date("d/m/Y",strtotime("+7 days",strtotime("next sunday")));