Jump to content

Subtract 1 Year


euel

Recommended Posts

Gud Pm!

Im trying to display a list of years (last year, current year and next year) with these simple code i made..

It displays the current and next year correctly except last year, which gives me "1970".

I don't get why it gives me that since may next year works properly..  :-\

 

$currentyear = date('Y');
$subtract_year = strtotime(date('Y', strtotime($currentyear)) . '-1 year');
$lastyear = date('Y', $subtract_year);
$addyear = strtotime(date('Y', strtotime($currentyear)) . '+1 year');
$newyear = date('Y', $addyear);
$year_array = array($lastyear, $currentyear, $newyear);
foreach($year_array as $year)
{
	echo "<option value='{$year}'>";
	echo $year;
	echo "</option>";
}

 

I'm not familiar with dates yet.. so i'm gonna read the manual while w8ting for your kind replies.  :)

Link to comment
https://forums.phpfreaks.com/topic/254459-subtract-1-year/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.