l_kris06 Posted December 22, 2008 Share Posted December 22, 2008 Hi all, I am generating a recurring instance of an .ics for outlook recurring meeting. I am stuck in a case where i need to get the next date from a week number and a weekday. for instance, curDate = 22/12/2008 weekDay = Wednesday weekNumber = 5 I need 31/12/2008 as return value. can somebody help? i think i am stuck. Rgds, Kris Link to comment https://forums.phpfreaks.com/topic/138032-get-date-from-weekday-and-weeknumber/ Share on other sites More sharing options...
Mark Baker Posted December 22, 2008 Share Posted December 22, 2008 $baseDate = strtotime('2008-12-22'); $dueDate = strtotime("next Wednesday",$baseDate); echo date('d-M-Y',$dueDate).'<br />'; may help But what is your weeknumber? What is the significance of 5? Link to comment https://forums.phpfreaks.com/topic/138032-get-date-from-weekday-and-weeknumber/#findComment-721416 Share on other sites More sharing options...
l_kris06 Posted December 22, 2008 Author Share Posted December 22, 2008 Hi Mark, The significance of the weeknumber in this case the value 5 is that I basically want the date of the 5th week on which the day is wednesday. Another example: curDate = 22/12/2008 weekDay = Friday weekNumber = 3 I would expect 19/12/2008 This is confusing, I dont knw how to go about it. Any help would be greatly appreciated. Best, Kris Link to comment https://forums.phpfreaks.com/topic/138032-get-date-from-weekday-and-weeknumber/#findComment-721467 Share on other sites More sharing options...
Mark Baker Posted December 22, 2008 Share Posted December 22, 2008 Quote I basically want the date of the 5th week on which the day is wednesday.The fifth week from what? I can only guess that you mean the start of the month 19th December 2008 was the 3rd Friday in the month 31st December is the 5th Wednesday in the month Is this correct? Link to comment https://forums.phpfreaks.com/topic/138032-get-date-from-weekday-and-weeknumber/#findComment-721491 Share on other sites More sharing options...
Mark Baker Posted December 22, 2008 Share Posted December 22, 2008 Based on that guess: $daysArray = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); $currentDate = time(); $weekDay = 'Wednesday'; $weekNumber = 5; $tmpWeekNbr = $weekNumber; switch ($tmpWeekNbr) { case 1 : $sup = 'st'; break; case 2 : $sup = 'nd'; break; case 3 : $sup = 'rd'; break; default : $sup = 'th'; } echo 'Current Date is '.date('d-M-Y',$currentDate).'<br />'; $dueDate = $baseDate = strtotime(date('Y-m',$currentDate).'-01'); echo 'Base Date is '.date('d-M-Y',$baseDate).'<br />'; $baseDoW = date('w',$baseDate); $requiredDoW = $daysArray[$weekDay]; echo 'Month starts on a '.$daysArray[$baseDoW].'<br />'; echo 'Day required is '.$weekDay.'<br />'; echo 'Week required is '.$weekNumber.'<br />';; if ($requiredDoW == $baseDoW) { $weekNumber--; } while ($weekNumber > 0) { $dueDate = strtotime('next '.$weekDay,$dueDate); $weekNumber--; } echo $tmpWeekNbr.$sup.' '.$weekDay.' in '.date('F',$dueDate).' is the '.date('d-M-Y',$dueDate).'<br />'; Based on this, you should be able to calculate for any month/year rather than just for the current month, and add some validation to the Day of Week and Week number so that the result doesn't spill over into the following month. Link to comment https://forums.phpfreaks.com/topic/138032-get-date-from-weekday-and-weeknumber/#findComment-721517 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.