I try to calculate a week with the following Code:

    $lastSun = strtotime('last Sunday');

    WriteLine("Last Sunday: ".date('Y.m.d',$lastSun));
    WriteLine(date('d.m.Y',$lastSun).' +1 days= '.date('d.m.Y',strtotime("+1 days last Sunday")));
    WriteLine(date('d.m.Y',$lastSun).' +2 days= '.date('d.m.Y',strtotime("+2 days last Sunday")));
    WriteLine(date('d.m.Y',$lastSun).' +3 days= '.date('d.m.Y',strtotime("+3 days last Sunday")));
    WriteLine(date('d.m.Y',$lastSun).' +4 days= '.date('d.m.Y',strtotime("+4 days last Sunday")));
    WriteLine(date('d.m.Y',$lastSun).' +5 days= '.date('d.m.Y',strtotime("+5 days last Sunday")));
    WriteLine(date('d.m.Y',$lastSun).' +6 days= '.date('d.m.Y',strtotime("+6 days last Sunday")));
    WriteLine(date('d.m.Y',$lastSun).' +7 days= '.date('d.m.Y',strtotime("+7 days last Sunday")));

But I a kind of suprising result when adding 7 days to the basis date:

Last Sunday: 2013.12.16

16.12.2013 +1 days= 16.12.2013
16.12.2013 +2 days= 17.12.2013
16.12.2013 +3 days= 18.12.2013
16.12.2013 +4 days= 19.12.2013
16.12.2013 +5 days= 20.12.2013
16.12.2013 +6 days= 21.12.2013
16.12.2013 +7 days= 29.12.2013

I tried it also with a hard-coded date instead the 'last sunday' but the result remains the same by adding 14 days instead of 7. So what did I missed or doing wrogn using the strtotime() function?

有帮助吗?

解决方案

try this way,

$sunday=strtotime("last Sunday");
$date = strtotime("+7 day", $sunday);

其他提示

You can give strtotime a parameter from which it calculates the given string.

strtotime("+7 days", $lastSun)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top