I have require first sunday date of every month using php code.
please can help me.
getSunday();
This is the best way to get first Sunday of the month
echo date("Y-m-d", strtotime("first Sunday of ".date('M')." ".date('Y').""));
You can use the Date/Time extension.
$start = new DateTime('2012-12-31');
$end = new DateTime('2013-12-31');
$interval = DateInterval::createFromDateString('first sunday of next month');
$period = new DatePeriod($start, $interval, $end, DatePeriod::EXCLUDE_START_DATE);
foreach($period as $time) {
echo $time->format("F jS") . "<br>\n";
}
/*
January 6th
February 3rd
March 3rd
April 7th
May 5th
June 2nd
July 7th
August 4th
September 1st
October 6th
November 3rd
December 1st
*/
function firstSunday($DATE)
{
$date = strftime("%Y-%m",$DATE);
$day = trim(strftime("%e",$DATE));
for($day; $day <= '7'; $day++){
$dd = strftime("%A",strtotime($date.'-'.$day));
if($dd == 'Sunday'){
return strftime("%Y-%m-%d",strtotime($date.'-'.$day));
}
}
}
I was looking for the DTS dates so here's how I found them:
$dtsStart = date('Y-m-d 02:00:00', strtotime('Second Sunday Of March 2015'));
$dtsEnd = date('Y-m-d 02:00:00', strtotime('First Sunday Of November 2015'));