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 Quote Link to comment 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) ; ?> Quote Link to comment 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 Quote Link to comment 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! Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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.