note 89175 deleted from function.date by derick
| From: | derick@php.net | Date: | Sun, 22 Mar 2009 18:43:22 +0000 |
| Subject: | note 89175 deleted from function.date by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-152288@lists.php.net to get a copy of this message | ||
Note Submitter: rsenthilbsc at gmail dot com
----
here i write the code to get all the date of sunday between two given dates
<?php
$start_date = '2008-06-01';
$end_date = '2009-03-31';
function getSundays($year)
{
$newyear = $year;
$week = 0;
$day = 1;
$mo = 1;
$mondays = array();
$i = 1;
while ($week != 1) {
$day++;
$week = date("w", mktime(0, 0, 0, $mo,$day, $year));
}
array_push($mondays,date("r", mktime(0, 0, 0, $mo,$day, $year)));
while ($newyear == $year) {
$test = strtotime(date("r", mktime(0, 0, 0, $mo,$day, $year)) . "+" . $i .
" week");
//echo $test."<br/>";
$i++;
if ($year == date("Y",$test)) {
array_push($mondays,date("r", $test));
}
$newyear = date("Y",$test);
}
return $mondays;
}
function ArrangeSundays($year) {
$mon_no[1] = '01';
$mon_ch[1] = 'Jan';
$mon_no[2] = '02';
$mon_ch[2] = 'Feb';
$mon_no[3] = '03';
$mon_ch[3] = 'Mar';
$mon_no[4] = '04';
$mon_ch[4] = 'Apr';
$mon_no[5] = '05';
$mon_ch[5] = 'May';
$mon_no[6] = '06';
$mon_ch[6] = 'Jun';
$mon_no[7] = '07';
$mon_ch[7] = 'Jun';
$mon_no[8] = '08';
$mon_ch[8] = 'Aug';
$mon_no[9] = '09';
$mon_ch[9] = 'Sep';
$mon_no[10] = '10';
$mon_ch[10] = 'Oct';
$mon_no[11] = '11';
$mon_ch[11] = 'Nov';
$mon_no[12] = '12';
$mon_ch[12] = 'Dec';
$sundays = $all_sundays_start = '';
$all_sundays_start = getSundays($year);
for($i=0; $i<count($all_sundays_start); $i++) {
$date_day = explode(" 00:00:00", $all_sundays_start[$i]); //Mon, 10 Mar 2008 00:00:00
+0000
$date = explode(", ", $date_day[0]); //Mon, 10 Mar 2008
$date_only = $date[1];
$$get_month_no = '';
$get_month_no = explode(" ", $date_only); //10 Mar 2008
$m = $get_month_no[1];
$y= $get_month_no[2];
$de= $get_month_no[0];
for($s=1; $s<=12; $s++) {
if($mon_ch[$s] == $m) {
$mo_nu= $mon_no[$s];
break;
}
}
$m=$mo_nu;
$sundays[$i] = date('Y-m-d', mktime(0,0,0,$m,($de-1),$y));
}
return $sundays;
}
function GetSundays_2Date($start_date, $end_date) {
$explode_1 = explode("-", $start_date);
$explode_2 = explode("-", $end_date);
$sm = $explode_1[1];
$sd = $explode_1[2];
$sy = $explode_1[0];
$em = $explode_2[1];
$ed = $explode_2[2];
$ey = $explode_2[0];
$start_sun_day = ArrangeSundays($sy);
$end_sun_day = ArrangeSundays($ey);
for($k=0; $k<count($start_sun_day); $k++) {
if($start_sun_day[$k] >= $start_date) {
$all_sundays[] = $start_sun_day[$k];
}
}
for($l=0; $l<count($end_sun_day); $l++) {
if($end_sun_day[$l] <= $end_date) {
$all_sundays[] = $end_sun_day[$l];
}
}
return $all_sundays;
}
$sundays_for_2_date = GetSundays_2Date($start_date, $end_date);
for($a=0; $a<count($sundays_for_2_date); $a++) {
echo $sundays_for_2_date[$a]."<br/>";
}
?>