leachus2002 Posted January 31, 2011 Share Posted January 31, 2011 Hi There, I want to be able to populate 2 variables, $previousmon and $previousfri with 2 dates, being the previous Monday and the previous Friday to the week you are on. So for example, if it is Monday 31st Jan, then $previousfri would be 28/01/2011 and $previousmon would be 24/01/2011. Is this easy enough to do? Cheers Matt Quote Link to comment https://forums.phpfreaks.com/topic/226211-finding-dates-and-placing-them-in-variables/ Share on other sites More sharing options...
suma237 Posted January 31, 2011 Share Posted January 31, 2011 //echo "previousfri would be 28/01/2011 and previousmon would be 24/01/2011."; $d = new DateTime(); $weekday = $d->format('w'); $diff = 7 + ($weekday == 0 ? 6 : $weekday - 1); // Monday=0, Sunday=6 $d->modify("-$diff day"); echo "previousmon". $d->format('Y-m-d') . ' - '; $d->modify('+4 day'); echo "<br>previousfri". $d->format('Y-m-d'); Quote Link to comment https://forums.phpfreaks.com/topic/226211-finding-dates-and-placing-them-in-variables/#findComment-1167756 Share on other sites More sharing options...
leachus2002 Posted January 31, 2011 Author Share Posted January 31, 2011 Like it, Thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/226211-finding-dates-and-placing-them-in-variables/#findComment-1167762 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.