hi,
i wrote a calendar in c++ a while back where the user just types the year they want and it draws a calendar for the given year. there are just a few things you want to mind when doing the calendar.
here is a formula to tell you what day jan 1 falls on for a given year:
(year + (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400) % 7
also you will need to know leap years, i wrote this function, its the shortest way ive seen to check for leap year:
function isLeapYear($year) { //boolean
return $year % 4 == 0 && $year % 100 != 0 || $year % 400 == 0;
}
also, of course you need to know how many days each month has.
jan - 31
feb - 28 or 29
mar - 31
apr - 30
may - 31
jun - 30
jul - 31
aug - 31
sep - 30
oct - 31
nov - 30
dec - 31
here is some c++ code for actually drawing the days. you need to know how many gaps there are before the first day of the month and then keep track of what day you are on. this shouldnt be too difficult to change to php, but if you cant, let me know.
(a few notes: "cout << " prints something. day_code variable is a return from the function that tells jan 1. setw will print spaces)
the code below resides in a for loop that covers all 12 months.
cout << "\n\nSun Mon Tue Wed Thu Fri Sat\n";
// Draw the top of the calendar
// advance to correct position for first day
for ( day = 1; day <= day_code * 5; day++ )
cout << " ";
// print the dates for one month
for ( day = 1; day <= days_in_month; day++ ) {
// field width is 3 because day names
// are 3 characters.
cout << setw(3) << day;
if ((day + day_code) % 7 > 0) // before Sat?
// move 2 spaces to next day in same week.
// (2 spaces separate the day names.)
cout << " ";
else // skip to next line to start with Sun
cout << endl;
}
// set day_code for next month to begin
day_code = (day_code + days_in_month) % 7;