?
Solved

Php Draw Calendar - 5 days, 7 days

Posted on 2012-09-20
6
Medium Priority
?
585 Views
Last Modified: 2012-09-20
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.
0
Comment
Question by:theRounder
6 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38418581
Sounds like a custom app.  There are many calendars available with a Google search.

See Practical Example #6 here:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html
0
 
LVL 45

Accepted Solution

by:
Chris Stanyon earned 1400 total points
ID: 38419007
Have a look at fullCalendar. It's a jQuery based front end (displaying your calendar, view by day, week, month, forward, back etc) and can be hooked into a backend script to populate the calendar from a database, add new data to the database etc. You can choose to show weekends or not - Pretty nice.

http://arshaw.com/fullcalendar/
0
 
LVL 9

Expert Comment

by:Derek Jensen
ID: 38419114
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:
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
    }
}

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 600 total points
ID: 38419187
skip the weekend days
Easy to do.  Render the day of the week with date('D') and skip the days that start with 'S' ;-)
0
 
LVL 9

Expert Comment

by:Derek Jensen
ID: 38419593
There ya go! ^_^
0
 

Author Closing Comment

by:theRounder
ID: 38420186
Thank you. Tried tons of google searched calendars and none came even close to Full calendar! Awesome find.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses
Course of the Month13 days, 9 hours left to enroll

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question