How to find a start date & end date of any given year & month

i really can't understand you clearly but to get the start date here is the code

date('Y-m-d');

this code above will get you the day of today and to get the end of the running month this code i used before

date(’Y-m-d’,strtotime(’-1 second’,strtotime(’+1 month’,strtotime(date(’m').’/01/’.date(’Y').’ 00:00:00′))));

i hope this help you in your issue


Use date (t format gives days in year) and create a time for it:

$year = 2011; $month = 6;

$starts = 1;
$ends = date('t', strtotime($month.'/'.$year)); //Returns days in month 6/2011

Start date will always be 1 and you can find the end date with the following function.

cal_days_in_month(CAL_GREGORIAN, $month, $year);

reference:

cal_days_in_month ( int $calendar , int $month , int $year ) : int


echo date('m-01-Y 00:00:00',strtotime('this month')) . '<br/>';
echo date('m-t-Y 12:59:59',strtotime('this month')) . '<br/>';

Tags:

Php