PHP: Week starts on Monday, but “monday this week” on a Sunday gets Monday next week

后端 未结 10 1503
误落风尘
误落风尘 2020-12-09 14:43

Here\'s a summary of the issue: On Sundays, strtotime(\'this week\') returns the start of next week.

In PHP, the week seems to start on Monday. But, on

10条回答
  •  旧时难觅i
    2020-12-09 15:20

    If you want the most recent monday:

    function mostRecentMonday(){
      if(date("w") == 1){
       return strtotime("midnight today");
      } else {
       return strtotime("last monday");
      }
    }
    

    Easy to modify to use DateTime, or, to even specify a different date to use as the base.

提交回复
热议问题