/***Finding the days of a week ***/
<?php
$out = pre();
$outpre=nextweek();
$td=date("Y-m-d");
$result = array_reverse($outpre);
//print_r($result);
array_push($result,$td);
$newarray = array_merge($result,$out);
foreach($newarray as $date1){
echo $date1;
echo "<br>";
}
//print_r($out);
//print_r($newarray);
function pre()
{
$monP=0;
$tueP=1;
$wedP=2;
$thuP=3;
$friP=4;
$satP=5;
$sunP=6;
$td=date("Y-m-d");
//echo $td;
$tdname=date("l");
switch($tdname)
{
case "Monday":
$rep=$monP;
break;
case "Tuesday":
$rep=$tueP;
break;
case "Wednesday":
$rep=$wedP;
break;
case "Thursday":
$rep=$thuP;
break;
case "Friday":
$rep=$friP;
break;
case "Saturday":
$rep=$satP;
break;
case "Sunday":
$rep=$sunP;
break;
default:
echo "Sorry";
}
//echo $tdname."<br>";
//echo $rep;
$datstart =$td; /* the starting date */
//$rep = 12; /* number of future dates to display */
$nod = 1; /* number of days in the future to increment the date */
$nom = 0; /* number of months in the future to increment the date */
$noy = 0; /* number of years in the future to increment the date */
$precon=future_date($datstart,$rep,$nod,$nom,$noy);
return $precon;
}
function future_date($datstart,$rep,$nod,$nom,$noy) {
$pre = array();
while ($rep >= 1) {
$datyy=substr($datstart,0,4);
$datmm=substr($datstart,5,2);
$datdd=substr($datstart,8,2);
$fda=$datdd - $nod;
$fmo=$datmm - $nom;
$fyr=$datyy -$noy;
$dat1=date("Y-m-d", mktime(0,0,0,$fmo,$fda,$fyr))."<BR>";
array_push($pre,$dat1);
//echo $dat1;
$datstart=$dat1;
$rep--;
}
return $pre;
}
function nextweek()
{
$monN=6;
$tueN=5;
$wedN=4;
$thuN=3;
$friN=2;
$satN=1;
$sunN=0;
$td=date("Y-m-d");
$tdname=date("l");
switch($tdname)
{
case "Monday":
$rep=$monN;
break;
case "Tuesday":
$rep=$tueN;
break;
case "Wednesday":
$rep=$wedN;
break;
case "Thursday":
$rep=$thuN;
break;
case "Friday":
$rep=$friN;
break;
case "Saturday":
$rep=$satN;
break;
case "Sunday":
$rep=$sunN;
break;
default:
echo "Sorry";
}
//echo $tdname."<br>";
//echo $rep;
$datstart =$td; /* the starting date */
//$rep = 12; /* number of future dates to display */
$nod = 1; /* number of days in the future to increment the date */
$nom = 0; /* number of months in the future to increment the date */
$noy = 0; /* number of years in the future to increment the date */
$con = future_date1($datstart,$rep,$nod,$nom,$noy);
return $con;
}
function future_date1($datstart,$rep,$nod,$nom,$noy) {
$pre = array();
while ($rep >= 1) {
$datyy=substr($datstart,0,4);
$datmm=substr($datstart,5,2);
$datdd=substr($datstart,8,2);
$fda=$datdd + $nod;
$fmo=$datmm + $nom;
$fyr=$datyy + $noy;
$dat1=date("Y-m-d", mktime(0,0,0,$fmo,$fda,$fyr))."<BR>";
array_push($pre,$dat1);
//echo $dat1;
$datstart=$dat1;
$rep--;
}
return $pre;
}
?>