knox203 Posted May 5, 2008 Share Posted May 5, 2008 Hey everyone, I have a script I found online that does exactly what I need it to do... but doesn't seem to be working for me when I try to print out the array. Can anyone point out what I'm doing wrong? Here's the code: <? /** * Function used to find the dates of specific days between * two different dates. So, if you want to find all the * mondays and all the wednesdays between 2 dates, this * function is right for you. * * @param string $startDate e.g. 2007-01-31 * @param string $endDate e.g. 2007-12-31 * @param csv string $days e.g. 'Su,M,T,W,TH,F,S'; * @return array */ $startDate = '2008-08-28'; $endDate = '2008-10-09'; $days = 'Mon'; function getDaysBetween($startDate, $endDate, $days) { $days = explode(',', $days); $dates = array(); foreach($days as $day) { $newDate = $startDate; switch ($day){ case 'Su': case 'Sun': $day = 'Sun'; break; case 'M': case 'Mon': $day = 'Mon'; break; case 'T': case 'Tu': case 'Tue': $day = 'Tue'; break; case 'W': case 'Wed': $day = 'Wed'; break; case 'Th': case 'Thu': case 'Thur': $day = 'Thu'; break; case 'F'; case 'Fri'; $day = 'Fri'; break; case 'S': case 'Sat': $day = 'Sat'; break; default: continue 2; } $curtime = strtotime("next $day", strtotime($startDate)); $endtime = strtotime($endDate); while($curtime <= $endtime) { $dates[] = date('Y-m-d', $curtime); $curtime = strtotime("next 2 $day", $curtime); } } $dates = array_unique($dates); sort($dates); return $dates; } ?> And I'm using <? print_r($dates); ?> to print out the array. Link to comment https://forums.phpfreaks.com/topic/104289-solved-grabbing-all-mondays-in-a-date-range-into-array/ Share on other sites More sharing options...
DarkWater Posted May 5, 2008 Share Posted May 5, 2008 You have to actually call the function. Naming your variables the same as the parameters doesn't do anything. =P Link to comment https://forums.phpfreaks.com/topic/104289-solved-grabbing-all-mondays-in-a-date-range-into-array/#findComment-533977 Share on other sites More sharing options...
knox203 Posted May 5, 2008 Author Share Posted May 5, 2008 Ahhh, that's why I love not paying for this site... I can feel like an idiot free of charge!! ... Could you clear up this whole calling the function ordeal for a noobie? Thanks! - Adam Link to comment https://forums.phpfreaks.com/topic/104289-solved-grabbing-all-mondays-in-a-date-range-into-array/#findComment-533980 Share on other sites More sharing options...
DarkWater Posted May 5, 2008 Share Posted May 5, 2008 Put this line after the function code and stuff. =P $dates = getDaysBetween($startDate, $endDate, $days); That only works because you have the variables set. Link to comment https://forums.phpfreaks.com/topic/104289-solved-grabbing-all-mondays-in-a-date-range-into-array/#findComment-533981 Share on other sites More sharing options...
knox203 Posted May 6, 2008 Author Share Posted May 6, 2008 Thanks so much Dark! Link to comment https://forums.phpfreaks.com/topic/104289-solved-grabbing-all-mondays-in-a-date-range-into-array/#findComment-533989 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.