refiking Posted November 4, 2008 Share Posted November 4, 2008 I've googled for this but have only found scripts that require you to given them a specific date and it tells you what day that is. I need something that can take a date in Y-m-d format and give me the date of the Monday of that week. Here's where I am right now: $time = time(); $today = date('Y-m-d 00:00:00', $time); //$monday = ???? Link to comment https://forums.phpfreaks.com/topic/131389-how-to-find-monday-of-a-given-week/ Share on other sites More sharing options...
F1Fan Posted November 4, 2008 Share Posted November 4, 2008 Something here should help you: http://www.w3schools.com/php/func_date_date.asp Link to comment https://forums.phpfreaks.com/topic/131389-how-to-find-monday-of-a-given-week/#findComment-682337 Share on other sites More sharing options...
kenrbnsn Posted November 4, 2008 Share Posted November 4, 2008 Try something like this: <?php $tomonday = array(0,0,-1,-2,-3,-4,-5,-6,1); echo "Monday's date this week is " . date('F jS, Y',strtotime($tomonday[date('N')] . ' days')); ?> Ken Link to comment https://forums.phpfreaks.com/topic/131389-how-to-find-monday-of-a-given-week/#findComment-682350 Share on other sites More sharing options...
refiking Posted November 4, 2008 Author Share Posted November 4, 2008 Thanks Ken. I already got something working based on the link F1Fan gave me. Although yours is a bit less verbose. Here's what I did: IF ($day = 'Monday'){ $mon = strtotime("$today"); $tue = strtotime("$today + 1 day"); $wed = strtotime("$today + 2 days"); $thur = strtotime("$today + 3 days"); $fri = strotime("$today + 4 days"); } IF ($day = 'Tuesday'){ $mon = strtotime("$today - 1 day"); $tue = strtotime("$today"); $wed = strtotime("$today + 1 day"); $thur = strtotime("$today + 2 days"); $fri = strtotime("$today + 3 days"); } IF ($day = 'Wednesday'){ $mon = strtotime("$today - 2 days"); $tue = strtotime("$today - 1 day"); $wed = strtotime("$today"); $thur = strtotime("$today + 1 day"); $fri = strtotime("$today + 2 days"); } IF ($day = 'Thursday'){ $mon = strtotime("$today - 3 days"); $tue = strtotime("$today - 2 days"); $wed = strtotime("$today - 1 day"); $thur = strtotime("$today"); $fri = strtotime("$today + 1 day"); } IF ($day = 'Friday'){ $mon = strtotime("$today - 4 days"); $tue = strtotime("$today - 3 days"); $wed = strtotime("$today - 2 days"); $thur = strtotime("$today - 1 day"); $fri = strtotime("$today"); } IF ($day = 'Saturday'){ $mon = strtotime("$today - 5 days"); $tue = strtotime("$today - 4 days"); $wed = strtotime("$today - 3 days"); $thur = strtotime("$today - 2 days"); $fri = strtotime("$today - 1 day"); } IF ($day = 'Sunday'){ $mon = strtotime("$today = 1 day"); $tue = strtotime("$today + 2 days"); $wed = strtotime("$today + 3 days"); $thur = strtotime("$today + 4 days"); $fri = strtotime("$today + 5 days"); } Link to comment https://forums.phpfreaks.com/topic/131389-how-to-find-monday-of-a-given-week/#findComment-682352 Share on other sites More sharing options...
kenrbnsn Posted November 4, 2008 Share Posted November 4, 2008 Your "if" statements are wrong. You're using a single "=" instead of the double "==" needed for comparison. Ken Link to comment https://forums.phpfreaks.com/topic/131389-how-to-find-monday-of-a-given-week/#findComment-682356 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.