/***Finding the days of a week ***/
<?php
$out = pre();
$outpre=nextweek();
$td=date("Y-m-d");
$result = array_reverse($outpre);
array_push($result,$td);
$newarray = array_merge($result,$out);
foreach($newarray as $date1){
echo $date1;
echo "<br>";
}
function pre()
{
$monP=0;
$tueP=1;
$wedP=2;
$thuP=3;
$friP=4;
$satP=5;
$sunP=6;
$td=date("Y-m-d");
$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";
}
$datstart =$td; $nod = 1; $nom = 0; $noy = 0; $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);
$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";
}
$datstart =$td; $nod = 1; $nom = 0; $noy = 0; $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);
$datstart=$dat1;
$rep--;
}
return $pre;
}
?>