Ellingsen Posted March 1, 2007 Share Posted March 1, 2007 Anyone kind enough to help me with this? i've searched trough sites and forums for it, but seems hard to find. If i have a week number of a year, like date('W Y'), and i need to find the date of the monday in that week, say week 28 2006, what date was monday? anyone got some info on this? all help appriciated Link to comment https://forums.phpfreaks.com/topic/40737-some-date-timestamp-mt_time-troubble/ Share on other sites More sharing options...
Barand Posted March 1, 2007 Share Posted March 1, 2007 I don't know any php function that accepts week as input to give date so you need to calculate it yourself Here's one way <?php function MondayOfWeekN($input) { list ($w, $y) = explode (' ', $input); $day1 = mktime(0,0,0,1,1,$y); // what day was it? $dow = date('w', $day1); // get date of first Monday $offset = ($dow+6)%7; $firstMonday = strtotime ("-$offset days", $day1); /** * now we know date of first monday * the Nth monday is that date + (N-1) * 7 days */ $n = ($w - 1) * 7; return date ('l jS F, Y', strtotime("+$n days", $firstMonday)); } echo MondayOfWeekN ("28 2006"); // --> Monday 3rd July, 2006 ?> Link to comment https://forums.phpfreaks.com/topic/40737-some-date-timestamp-mt_time-troubble/#findComment-197308 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.