php - Previous and next month not working as expected -


i have following code in order create previous , next month links:

$date = mktime( 0, 0, 0, date("m"), 1, date("y") ); $nextmonth  = strftime( '%b', strtotime( '+1 month', $date ) ); $prevmonth  = strftime( '%b', strtotime( '-1 month', $date ) ); $nextyear   = strftime( '%y', strtotime( '+1 month', $date ) ); $prevyear   = strftime( '%y', strtotime( '-1 month', $date ) ); 

now when december

 next year variable 2016  previous year variable 2015 

but when date january 2016

 next year variable 2015  previous year variable 2014 

i can't understand why doing or doing wrong here. 1 have idea how fix this?

testing function fixed parameters, you'll :

$date = mktime( 0, 0, 0, 1, 1, 2016); 

and echo $nextyear not give 2016 because added 1 month. testing what's scripted :

the next year variable 2016 // january 2016 + 1 month = february 2016 previous year variable 2015 // jan 2016 - 1 month = dec 2015 

my guess passing date('y') without realizing it's 2015


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -