problem with php calendar navigation
Posted: Thu Dec 31, 2009 7:07 am
I am designing calendar using PHP. I have problem with navigation designing. I am using following concept to find out next month, previous month, next year, previous year.
Initially, I am calling the above function with current year, month, and day. After that I am passing values based on navigation.
Basically, I am designing this navigation to have a links to say next month, previous month, next year, previous year. When I click on next month, it should take me the current date of next month which is similar to how windows system calendar works.
I am facing the problem, while accessing the script on month ending dates i.e. 31st. problem is: it get failed to provide the navigation for next immediate month. For example, if I am running on Dec 31, it’s giving Jan -> March -> May …. It failed to give month between that. When I am working in non month end date, it is working perfect.
Please let me know if you find some mistake in my calculation.
Code: Select all
function showNav($year, $month, $day) {
$next_m = date ( "m", mktime ( 0, 0, 0, $month + 1, $day, $year ) );
$next_y = date ( "Y", mktime ( 0, 0, 0, $month, $day, $year + 1 ) );
$prev_m = date ( "m", mktime ( 0, 0, 0, $month - 1, $day, $year ) );
$prev_y = date ( "Y", mktime ( 0, 0, 0, $month, $day, $year - 1 ) );
……
}Basically, I am designing this navigation to have a links to say next month, previous month, next year, previous year. When I click on next month, it should take me the current date of next month which is similar to how windows system calendar works.
I am facing the problem, while accessing the script on month ending dates i.e. 31st. problem is: it get failed to provide the navigation for next immediate month. For example, if I am running on Dec 31, it’s giving Jan -> March -> May …. It failed to give month between that. When I am working in non month end date, it is working perfect.
Please let me know if you find some mistake in my calculation.