note 81529 added to function.strtotime

From: Date: Mon, 03 Mar 2008 06:35:42 +0000
Subject: note 81529 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-136678@lists.php.net to get a copy of this message
Just an correction to Jeff Stevenson's function of 2008-02-02. That code as is didn't really work, but the right idea was there.. (e.g., the $days parameter wasn't really used, and the sort didn't save) There were a few typos and minor other things, try the code below instead... 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; } ---- Server IP: 66.207.199.35 Probable Submitter: 99.237.218.150 ---- Manual Page -- http://www.php.net/manual/en/function.strtotime.php Edit -- https://master.php.net/note/edit/81529 Del: integrated -- https://master.php.net/note/delete/81529/integrated Del: useless -- https://master.php.net/note/delete/81529/useless Del: bad code -- https://master.php.net/note/delete/81529/bad+code Del: spam -- https://master.php.net/note/delete/81529/spam Del: non-english -- https://master.php.net/note/delete/81529/non-english Del: in docs -- https://master.php.net/note/delete/81529/in+docs Del: other reasons-- https://master.php.net/note/delete/81529 Reject -- https://master.php.net/note/reject/81529 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#136678) next »