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 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'); 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! 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
Archived
This topic is now archived and is closed to further replies.