theRounder
asked on
Php Draw Calendar - 5 days, 7 days
Hello php experts;
Having some trouble with this one.
I am trying to draw a calendar <Table> with an option to either draw a 5 day or 7 day calendar, with the 5 day, obviously excluding the weekends.
To make it even more interesting, I would like to include previous and next month dates to populate the "spaces", if there are any, at the beginning and end of the month.
For Example:
January 2013
31 01 02 03 04
07 08 09 10 11
14 15 16 17 18
21 22 23 24 25
28 29 30 31 01
Maybe this is simple and I am overlooking something.
Having some trouble with this one.
I am trying to draw a calendar <Table> with an option to either draw a 5 day or 7 day calendar, with the 5 day, obviously excluding the weekends.
To make it even more interesting, I would like to include previous and next month dates to populate the "spaces", if there are any, at the beginning and end of the month.
For Example:
January 2013
31 01 02 03 04
07 08 09 10 11
14 15 16 17 18
21 22 23 24 25
28 29 30 31 01
Maybe this is simple and I am overlooking something.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You've got 2 fundamental problems here:
Finding the start day(must be done first), and
looping through the remainder of the calendar days, based on user's selection.
There are plethora ways to find the start day, so I'll leave that up to you. :-)
Once you have the start day, if you wanted to display the days preceding the start day from the prior month, you'd need to determine the prior month, then how many days it has, then simply count backwards until you reach the start of the week.
The start of the week would be determined, of course, by the user's selection of 5 or 7 day weeks. However, you're still going to loop through every single day of the month; this is the easiest way to guarantee the date remains correct, regardless of layout.
If 5 day layout is chosen, you'd simply skip the weekend days.
Here's the easiest way I see it, in simple pseudo:
Finding the start day(must be done first), and
looping through the remainder of the calendar days, based on user's selection.
There are plethora ways to find the start day, so I'll leave that up to you. :-)
Once you have the start day, if you wanted to display the days preceding the start day from the prior month, you'd need to determine the prior month, then how many days it has, then simply count backwards until you reach the start of the week.
The start of the week would be determined, of course, by the user's selection of 5 or 7 day weeks. However, you're still going to loop through every single day of the month; this is the easiest way to guarantee the date remains correct, regardless of layout.
If 5 day layout is chosen, you'd simply skip the weekend days.
Here's the easiest way I see it, in simple pseudo:
EndOfMonth = false;
myDate = 0;
TotalDays = getDaysOfMonth(currMonth);
while (!EndOfMonth) {
foreach (weekday as day) {
myDate++;
if (myDate >= TotalDays) {EndOfMonth = true;}
// Other stuff here, including check if 5-day layout on weekdays
}
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
There ya go! ^_^
ASKER
Thank you. Tried tons of google searched calendars and none came even close to Full calendar! Awesome find.
See Practical Example #6 here:
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html