+91-943-185-6038 me@shashidharkumar.com

Get the First Monday of the current Month or Get Last Day of Month or Get First Day of Month
Get the First Monday of the current Month
<?php
function getFirstMonday($month,$year)
{
$num = date(“w”,mktime(0,0,0,$month,1,$year));
if($num==1)
return date(“Y-M-ds”,mktime(0,0,0,$month,1,$year));
elseif($num>1)
return date(“Y-M-d”,mktime(0,0,0,$month,1,$year)+(86400*(8-$num)));
else
return date(“Y-M-d”,mktime(0,0,0,$month,1,$year)+(86400*(1-$num)));
}
$month = date(“m”);
$year = date(“Y”);
// this will output current month’s First Monday
echo getFirstMonday($month,$year);
?>


Get the Last Day of current Month
<?php
echo date(‘d/m/y’,strtotime(“last Friday”,mktime(0,0,0,date(“n”)+1,1))); // you can replace your Day instead of ‘Friday’ to get the desired last day
?>

Get the First weekday of current Month
<?php
$month = date(“m”); // you can change with your own value
$year = date(“Y”); // you can change with your own value
echo “First weekday of month “.$firstWeekDayOfMonth = date(“l”, mktime(0, 0, 0, $month, 1, $year));
?>

Get First Day of Month
<?php
/*
$dayNumber=5; can be change according your requirement as per following
1) if you want first day of the month is Monday than you can use $day_number=1;
2) if you want first day of the month is Tuesday than you can use $day_number=2;
3) if you want first day of the month is Wednesday than you can use $day_number=3;
4) if you want first day of the month is Thursday than you can use $day_number=4;
5) if you want first day of the month is Friday than you can use $day_number=5;
6) if you want first day of the month is Saturday than you can use $day_number=6;
7) if you want first day of the month is Sunday than you can use $day_number=7;
*/
function getFirstDay($dayNumber=1, $month=false, $year=false)
{
$month = ($month === false) ? strftime(“%m”): $month; // if $month is set false than get current month
$year = ($year === false) ? strftime(“%Y”): $year; // if $year is set false than get current year
$firstDay = 1 + ((7+$dayNumber – strftime(“%w”, mktime(0,0,0,$month, 1, $year)))%7);
return mktime(0,0,0,$month, $firstDay, $year);
}
// this will output the first Monday of current month and current year
// i.e. today’s month and year is February 2011, output will 04/02/2011
echo “First Monday: “.strftime(“%d/%m/%Y”, getFirstDay());
?>

See also  Redirect HTTP to HTTPS Apache secure connection