![]() |
Calendar help
Hey!
I'm building a calendar class. It works quite well with getting the current month. Now I want to develop a system/function that makes it possible to change the month or year to future or history. php Code:
Month is a class that handles the month and calculates the days/weeks/blank days/etc. You don't have to care about that. As you see I'm calling it via month() where I want to be able to set month and year. If only month is specified it should display the month that was set, with the current year(since that wasn't set). And if only year is set it should display the current month(since month wasn't set) but the year that was set. If that makes any sense. Any ideas how to solve that? |
Very simple to do just add or subtract to the current timestamp
When changing months + or - you just add or subtract (2678400 * (Number of months)) For a year you would + or minus (31556908 * (Number of Years)) The two numbers 2678400 - Is the number of seconds in a day 31556908 - Number of seconds in a year. For example a year would be PHP Code:
PHP Code:
|
I understand the concept of it, but.. how would I do so I can call it like:
PHP Code:
I understand the concept you posted, I just don't know how to.. apply it to what I want. |
You can use the following function http://us.php.net/date_parse and http://us.php.net/mktime To convert those dates into a timestamp instead of doing the math calculations :)
|
Worked great!
php Code:
How would you suggest I do the "navigation" of this calendar? So people can press like "next month", "next year", "last month", "last year", etc. Should I do that with GET? |
Another solution would be to use PHP's DateTime class to manipulate dates.
PHP Code:
|
Mhm, that would work aswell, though I used the first one.
Anyhow. I have another problem here. I created this class, and right now Sunday is the beginning of the week when I output the calendar. How would I change it so it's Monday instead? Edit: Nvm. Solved it. |
| All times are GMT. The time now is 07:06 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0