note 56899 added to function.date

From: Date: Mon, 19 Sep 2005 02:45:48 +0000
Subject: note 56899 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-95387@lists.php.net to get a copy of this message
<?php /* This will return the N possible future dates acording to your selections of parameters mydates_array([Which Week in a Month],[Which Day in a Week],[No of Dates have to return]) Eg:- Every 2nd Sunday mydates_array(2,0,10) $Dateid---> Sunday - 0 , Monday - 1 , Tuesday - 2, Wednesday - 3, Thursday - 4 , Friday - 5 , Saturday - 6 $weekid---> * can not be greater than 6 * if weekID is equal 6 it will return the Last Day of the weeek. * Eg:-mydates_array(6,1,10); * it will Returns 10 Last Mondays * Please note weekid 5 is not availble in all months.mydates_array will not returns $no_returns that you want. * Eg:-mydates_array(5,1,10); * it will Returns 5th Monday $no_returns--> No of dates that you want By: Rajaratnam Thavakumar(thava16@hotmail.com) */ function mydates_array($weekid,$Dateid,$no_returns){ if($weekid<=6){ $todayweek = date("D"); $myarr=array("Sun","Mon","Tue","Wed","Thu","Fri","Sat"); for($k=0;$k<=6;$k++){ if ($todayweek==$myarr[$k]){ if($k==0){ $currentdate=0; }else{ $currentdate=$k; } } } //get Dateid ---------------- if($Dateid==0){ $Newmyday=date("d")-$currentdate; }else if ($Dateid==1){ $Newmyday=date("d")-($currentdate-1); }else if ($Dateid==2){ $Newmyday=date("d")-($currentdate-2); }else if ($Dateid==3){ $Newmyday=date("d")-($currentdate-3); }else if ($Dateid==4){ $Newmyday=date("d")-($currentdate-4); }else if ($Dateid==5){ $Newmyday=date("d")-($currentdate-5); }else if ($Dateid==6){ $Newmyday=date("d")-($currentdate-6); } $thisweekId=$weekid; $count=0; $column=0; $myval=$no_returns*5; for($i=1; $i<=$myval; $i++){ $week1a = mktime(0, 0, 0, date("m"), $Newmyday, date("Y")); $week123=strftime("%Y-%m-%d", $week1a); $Newmyday=$Newmyday+7; list ($iyear, $imonth, $idate) = split ('[-.-]', $week123); //Insert Dates into Array if( $idate<10){ $idate=trim(str_replace('0','',$idate)); } $myweekno=ceil(($idate + date("w",mktime(0,0,0,$imonth,0,$iyear)))/7); $row=$myweekno-1; $Mymonth[$i]=$imonth; if ($i>1){ if ($Mymonth[$i-1]!=$Mymonth[$i]){ $column=$column+1; } } $EveDates[$row][$column]=$week123; } $count=0; for ( $column = 0; $column < $no_returns; $column++ ){ //--for1----- $mynewcount=0; for($row = 0; $row < 6; $row++){ //--for2----- if($EveDates[$row][$column]!="" && $thisweekId!=6){ list ($iyear1, $imonth1, $idate1) = split ('[-.-]', $EveDates[$row][$column]); $myweekno=ceil(($idate1 + date("w",mktime(0,0,0,$imonth1,0,$iyear1)))/7); $mynewcount=$mynewcount+1; if($mynewcount==$thisweekId){ $week_n1= mktime(0, 0, 0, date("m"), date("d"), date("Y")); $week_m1=strftime("%Y-%m-%d", $week_n1); if($count < $no_returns && $EveDates[$row][$column] >= $week_m1){ $mydates_array[$count]=$EveDates[$row][$column]; } $count=$count+1; } } else{ $mycount=0; if ($row==5 && $thisweekId==6){ for($e=5; $e>=0; $e--){ if($EveDates[$e][$column]!=""){ break; } } $week_n1= mktime(0, 0, 0, date("m"), date("d"), date("Y")); $week_m1=strftime("%Y-%m-%d", $week_n1); if($mycount<$no_returns && $EveDates[$e][$column] >= $week_m1){ $mydates_array[$count]=$EveDates[$e][$column]; } $mycount=$mycount+1; $count=$count+1; } } } //--End of for2----- } //--End of for1----- return $mydates_array; }else{ echo('WeekID Cant be more than six!'); }} ?> <select name="eventDate" style="border:1 solid #000066" > <? // Return 10 Every 2nd Monday dates $myarray=mydates_array(2,1,10); for ($i=0;$i<count($myarray);$i++){ list ($iyear, $imonth, $idate) = split ('[-.-]', $myarray[$i]); $week1a = mktime(0, 0, 0,$imonth, $idate, $iyear); $week= strftime("%A %d %B %Y", $week1a); ?> <option value="<?=$myarray[$i]?>"><?=$week?></option> <? }?> </select> ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+56899 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56899&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56899&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56899&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56899&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56899&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+56899&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56899&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+56899&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#95387) next »