Suppose there are 10 weeks; week_1st, week_2nd, week_3rd ... , week_10th. week_10th starts at 2014-05-01 00:00:00 , how can i find the start date of week_5th (the past week) ? would you please show me in php ? thank you very much.
1条回答 默认 最新
- duankange2433 2014-04-23 21:08关注
If you want to go exactly 5 weeks back (or something), try:
$date = new DateTime('2014-05-01'); $date->modify('-5 weeks'); echo $date->format('Y-m-d');
If you want to always get the monday (or similar) you can try
$date = new DateTime('2014-05-01'); $day = (int)$date->format('w'); $date->modify('-5 weeks'); $date->modify( 1 - $day . ' days'); // 1 = Monday echo $date->format('Y-m-d');
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报