I have problem in php find start date & end date of month & year , when i know the year and month ?
ex:
input - > year = 2011 , month = 0
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
echo date('m-01-Y 00:00:00',strtotime('this month')) . '<br/>';
echo date('m-t-Y 12:59:59',strtotime('this month')) . '<br/>';
$year = '2017';
$month = '05';
echo date("$year-$month-01");
echo "<br>";
echo date("$year-$month-t");
shortest solution in my own opinion.
PHP may have a more elegant way of doing this, but if you want a generic algorithm, here's what you need to do...
All months other than February have a fixed number of days. February has 29 only when it's a leap year. Here are the rules to check if it's a leap year:
You should look into strtotime:
echo date("D, M j, Y", strtotime("FIRST DAY OF MAY 2012"));
// Tue, May 1, 2012
echo date("D, M j, Y", strtotime("last DAY june 2012")); // gotcha! using June.
// Thu, May 31, 2012