project3 Posted March 7, 2008 Share Posted March 7, 2008 Im looking to get the week begining(monday - sunday) and ending date give todays date. $today = date("m/d/Y"); Im sure you probably use mktime but Ive been able to get that to work. thanks in advance Link to comment https://forums.phpfreaks.com/topic/94826-finding-week-begining-and-ending-days/ Share on other sites More sharing options...
Barand Posted March 7, 2008 Share Posted March 7, 2008 <?php $dayOfWk = (date('w') + 6) % 7; $wkStart = strtotime("-$dayOfWk days"); $wkEnd = strtotime("+6days", $wkStart); echo "Week is " . date ('D m/d/Y', $wkStart) . " to " . date ('D m/d/Y', $wkEnd) ; ?> Link to comment https://forums.phpfreaks.com/topic/94826-finding-week-begining-and-ending-days/#findComment-485688 Share on other sites More sharing options...
kenrbnsn Posted March 7, 2008 Share Posted March 7, 2008 You can also do: <?php $lm = strtotime('last monday'); $ns = strtotime('next sunday'); echo 'Today: ' . date('l, F jS, Y') . '<br>'; echo 'Start of week: ' . date('l, F jS, Y',$lm) . '<br>'; echo 'End of week: ' . date('l, F jS, Y',$ns) . '<br>'; ?> Ken Link to comment https://forums.phpfreaks.com/topic/94826-finding-week-begining-and-ending-days/#findComment-485697 Share on other sites More sharing options...
project3 Posted March 7, 2008 Author Share Posted March 7, 2008 <?php $dayOfWk = (date('w') + 6) % 7; $wkStart = strtotime("-$dayOfWk days"); $wkEnd = strtotime("+6days", $wkStart); echo "Week is " . date ('D m/d/Y', $wkStart) . " to " . date ('D m/d/Y', $wkEnd) ; ?> Thanks Barand worked perfectly! Link to comment https://forums.phpfreaks.com/topic/94826-finding-week-begining-and-ending-days/#findComment-485699 Share on other sites More sharing options...
Barand Posted March 7, 2008 Share Posted March 7, 2008 ken, If today is Monday, "last Monday" gives the previous Monday? <?php $lf = strtotime("last friday"); echo date ('d/m/y', $lf); ?> --> 29/02/08 Link to comment https://forums.phpfreaks.com/topic/94826-finding-week-begining-and-ending-days/#findComment-485710 Share on other sites More sharing options...
kenrbnsn Posted March 7, 2008 Share Posted March 7, 2008 You're correct -- that's one of the drawbacks with strtotime(). Ken Link to comment https://forums.phpfreaks.com/topic/94826-finding-week-begining-and-ending-days/#findComment-485715 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.