euel Posted January 6, 2012 Share Posted January 6, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/254459-subtract-1-year/ Share on other sites More sharing options...
scootstah Posted January 6, 2012 Share Posted January 6, 2012 All you need is this: $lastyear = date('Y', strtotime('-1 year')); Quote Link to comment https://forums.phpfreaks.com/topic/254459-subtract-1-year/#findComment-1304718 Share on other sites More sharing options...
euel Posted January 6, 2012 Author Share Posted January 6, 2012 thanks scootstah! i also replaced my newyear with it. Quote Link to comment https://forums.phpfreaks.com/topic/254459-subtract-1-year/#findComment-1304720 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.