dongpao5658 2013-12-22 10:56
浏览 568
已采纳

php strtotime +7天问题

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?

  • 写回答

2条回答 默认 最新

  • doutizong8099 2013-12-22 11:02
    关注

    try this way,

    $sunday=strtotime("last Sunday");
    $date = strtotime("+7 day", $sunday);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件
  • ¥15 使用ESP8266连接阿里云出现问题
  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人