How can i get the last day of a year passed as parameter using strtotime?
I try this but the results are not the correct last days :
$yearEnd2015 = date('Y-m-d', strtotime('last day of december this year -3'));
$yearEnd2016 = date('Y-m-d', strtotime('last day of december this year -2'));
$yearEnd2017 = date('Y-m-d', strtotime('last day of december this year -1'));
$yearEnd = date('Y-m-d', strtotime('last day of december this year'));
echo " <br>2015 : ".$yearEnd2015;
echo " <br>2016 : ".$yearEnd2016;
echo " <br>2017 : ".$yearEnd2017;
echo " <br>2018 : ".$yearEnd;
You can do it like this, just send the last day in the year(31 Dec) to the strtotime
function, for example to get the date name of the last day in 2015:
$yearEnd2015 = date('l', strtotime('2015-12-31'));
echo $yearEnd2015;
Or you can store the desired year in a variable(if you want to use it in a function or the year changes dynamically): for example to get all the last date names from 2000 till now:
$year = 2000;
while($year++ <= 2018) {
$yearEnd = date('l', strtotime($year . '-12-31'));
echo $yearEnd . '<br />';
}
Hope I pushed you further.
i think you get year from user input . u refer this one
$lastdate="-12-31";
$year=$_POST['year'];//lets say you get yearr from post
$day=date('l',strtotime($year.$lastdate));
echo $day;
You don't even need strtotime (even though you could definitely use it). If you get the year as an input parameter:
$year = '2018';
$lastday = date($year.'-12-31');
echo $lastday;
This is a simple hack that only works because you're actually building the same calendar date and only changing the year. But does the trick for what you need
echo date('l',strtotime(date('Y')));
You need to write code like this
$yearEnd2015 = date('Y-m-d D', strtotime('2015-12-31'));
$yearEnd2016 = date('Y-m-d D', strtotime('2016-12-31'));
$yearEnd2017 = date('Y-m-d D', strtotime('2017-12-31'));
$yearEnd = date('Y-m-d D', strtotime('2018-12-31'));
echo " <br>2015 : ".$yearEnd2015;
echo " <br>2016 : ".$yearEnd2016;
echo " <br>2017 : ".$yearEnd2017;
echo " <br>2018 : ".$yearEnd;