Intranet Journal   Earthweb  
Images Events Jobs Premium Services Media Kit Network Map E-mail Offers Vendor Solutions Webcasts

   Intranet Journal Subjects
Search Earthweb

Privacy Policy



internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

internet commerce
Be a Commerce Partner
















 

[ Home | Discussion Forum | How Do I... | Lotus Notes Intranets | Microsoft SharePoint | Products | Shopping  ]

free news!

Building an Event Calendar


By Samuel Pickard
There are many systems that I can think of which would benefit from having a shared calendar into which users can log and read events. Almost any group based project, whether running on an intranet or over the Internet could make use of it. So, following Matthew Reynolds' suggestion, I wrote some code to produce it.

Supporting database structure

For our event calendar, we need an extremely simple database. In fact it only has one table and three fields.
Table: Events
EventID Integer
EventText Text (or Memo)
EventDate DateTime


I have built my database in SQL Server 6.5, but you could use any system with ODBC drivers. I have included the schema for download.

Handling dates across different date systems
When I was planning this project, one of my biggest factors was that it dealt with dates, but would have to work on anyone's server. I am sure that I am not alone when I get frustrated when I have to use a date format which is not native to me. Fortunately, Microsoft have put a lot of work into date handling, and have made VBScript as format independent as is reasonable. With all the date functions in VBScript, you can specify the date that you want to consider the first day of the week. For example

WeekDay(date, vbSunday)


This line will tell which day of the week the given date will fall, starting from Sunday. The default however is

WeekDay(date, 0)


Which will tell you the day of the week, based on the date settings on the server. For this project, all dates are linked to the server settings.

Rendering your calendar to screen
Probably the hardest part of this project is to get your monthly calendar view onto the screen. Finding the current date is easy. VBScript provides a function called Date() which returns the current system date. From there, the next step is also easy. As part of the date functions, VBScript also gives you
Month( date)

and
Year(date)


both of which will extract the month and date parts from a date, based on the formats held on the server. One other useful function will also give you the name of the month.

MonthName(month)


Again, this is from the system settings. From MonthName(1) I will get 'January', but someone with a French server will get 'Janvier'.

From this, we can start the HTML Table that will hold our month view.

EventDate = date
CurrentMonth = Month(EventDate)
CurrentMonthName = MonthName(CurrentMonth) '
CurrentYear = Year(EventDate)

<TABLE COLS="7" BORDER="1">
<TR>
 <TD>
   <TD COLSPAN="7" ALIGN="CENTER">
       <%= CurrentMonthName %>
   </TD>
 </TR>


Easy. Now, what we want to do is to output the names of the days, independently of language or dating convention. Fortunatly, Microsoft has done the hard bits on this as well. The VBScript function WeekDayName provides this. You can pass it a day of the week, and it will return the name of that day. It will also return an abbreviated version of the name, so rather than it giving me 'Monday', it will give me 'Mon'.

<TR>
<% For DayLoop = 1 to 7%>
   <TD><%= WeekDayName(Dayloop, True, 0)%></TD>
<% Next%>
</TR>


The order that the names are retreived in is also dependent on the language setting of the server. In the UK, my code will list the days from Monday to Sunday. A server running in the US will list them from Sunday to Saturday.

Ok. Now we are getting to the nitty-gritty. We need to put the correct date underneath the correct day. What we actually need is to know on which day of the week, the first day of that month falls.

FirstDayDate = DateSerial(CurrentYear, CurrentMonth, 1)
FirstDay = WeekDay(FirstDayDate, 0)
CurrentDay = FirstDayDate


Let's get some more information. We can use the VBScript function DateSerial to create a variable FirstDayDate. DateSerial will format the year, month and date and return it in date format. We have already defined CurrentYear and CurrentMonth earlier on. We want to use 1, because it is the first of the month we are after.

WeekDay will return the number of the day that corresponds to the server settings for the week order, and matches the week list we have already generated. For instance if Wednesday is the third day on your list, running WeekDay on a date that you know falls on a Wednesday will return 3.

We alse need CurrentDay as we move though the month.

We can now pad out the blanks at the beginning of calendar.

<% If FirstDay <> 1 Then %>
 <TDColspan="<%=FirstDay -1%>">
<% End if %>


We don't want any padding if the first day of the month is the same as the first day of the week. We also only want to pad upto the first day of the week, so we can span one table data element FirstDay-1 columns to bring us into line.

At the end of each week, we want to start a new row. I have created a variable which will keep track of how many days through the week we are. As we have already moved partway through the first week, we need to initialise it to a starting value.

DayCounter = FirstDay


We are also going to stop showing the days when we hit the end of the month.

CorrectMonth = True


Ok. Let's do the main loop.

<%
Do While CorrectMonth = True
%>
<TD>
  <%=Day(CurrentDay)%>
</TD>

<%
DayCounter = DayCounter + 1

If DayCounter > 7 then
   DayCounter = 1%>
   </TR><TR>
<%
End if

CurrentDay = DateAdd("d", 1, CurrentDay)

If Month(CurrentDay) <> CurrentMonth then
   CorrectMonth = False
End if
Loop
%>

This should be fairly simple, but let's step through it. We are only going to keep doing the loop whilst we are in the target month, so it is while CorrectMonth is True. We can write out each day to a new table data cell. Once we have done that we need to move DayCounter along. If we have done the seven days, we need to close the table row and start a new one. We also need to move then date variable onto the next day. To do this, you can use the DateAdd function which will add a time period ("d" for "day"), the number of units (1) and an original date. If by moving onto this day we are into the next month, set CurrentMonth to False and exit the loop.



Next Page of this Article

Previous Article: Creation and Maintenance of Appealing ASP Pages with Dynamically Generated Contents

Index: Active Server Pages\IIS


The Author


Samuel Pickard is an old school client/server programmer who made the move from programming in C/ESQL on UNIX to the easy life writing ASP. He has produced many ASP projects over the last few years, but now specialises in creating on-line magazines. Samuel also trains a lot of new developers in ASP/ADO who promptly get tempted to go to London for 'a measly 100% payrise'. Samuel stays well clear of Site Server, and hopes one day to have a better dev server.



[print version of this page]

Of Interest
· Post and answer questions with the experts at Intranet Journal's discussion Intranet Discussion Forum, the eXchange.




 Intranet News 
* Intranet/Internet Product Summary: January 04, 2001
* Red Herring Picks Plumtree for Employee Portal
* Tideworks Goes with Intranet from Eprise
* Crayfish Nabs 47 Percent of Intranets.com's Japan Arm
* IntraNet Solutions Notches Belt with Oakwood
* BT Secures Corporate Portal Help from Plumtree
* Mobilize Offers Enterprise App to Lexis-Nexis

More News

In' tra net - n. 1) a computer network connecting an affiliated set of clients using standard internet protocols, esp. TCP/IP and HTTP. 2) an IP-based network of nodes behind a firewall, or behind several firewalls connected by secure, possibly virtual, networks.
  IDM Unwired  
IDM on the Road
NOW AN OFFICIAL AVANTGO CHANNEL!
To easily add IDM to your PDA
click here

Featured Archive Articles

  •  Putting Your Intranet to Work: 50 Ideas for Department-Specific Applications
  •   Five-steps to implement your intranet and manage your strategic information
  •  A new generation of intranet tools intersects Customer Relationship Management and Sales Force Automation
  •   Business Intelligence and the Intranet
  •  Effective Intranet Publishing: Getting Critical Knowledge to Any Employee, Anywhere


  •   Using an Intranet to Manage 610,000 animal specimens with Java
  •  Putting JavaScript to Work for Your Intranet
  •   JavaScript Forms and Frames
  •  Introduction to the Browser Object Model
  •  Black Hole Sun: Java is Going Supernova Thanks to its Creator's Gravitational Pull


  •   Managing Large Collections of Documents: A full-length excerpt from the book "Intranet Document Management."
  •  Intranet Traffic Management: Without Quality of Service standards, intranets and extranets face death by success
  •  Issues in Intranet Security: A primer on keeping the keys to the enterprise safe


  •   Report from the trenches: Firms weigh in on intranet deployment trends
  •  The Magna Carta of the Intranet: From Smart Companies, Smart Tools
  •   Prudential HealthCare Launches Extranet to Manage Health Benefits
  •   Wells Fargo Unit Looks To Establish Its Intranet as a 'Portal'
  •   Amkor/Anam's intranet is a study in open systems integration


  •  Tutorial: Finding Your Way Around E-commerce
  •   The Essential Supply Chain
  •  A Definition of Data Warehousing
  •   Internet Messaging: from the Desktop to the Enterprise


  •  Improving Intranet Information Retrieval with Human Indexing
  •   An XML Development Kit
  •   When To Use Active Server Pages
  •  Intranets and extranets for virtual project management
  •  Why Groupware is Hard
  •  Optimizing Web Pages For Handheld Devices


  •  Version Control within a Collaborative Extranet
  •   Electronic Procurement, Extranets and You
  •  Intranet and extranets for virtual project management
  •  Overview of Virtual Private Networks


  •  What's the Future of Application Service Vendors?
  •  'Enterprise Portal' - a New Catch Phrase, But Definitions Vary
  •   Portals, You Say? This One's Private Ericsson's intranet is a give-and-take affair with employees
  •  Application Hosting

Elsewhere on internet.com
*  What Happened at XML 2000?
*  Collaborative Computing: This Changes Everything
*  inFusion: Bringing ColdFusion to a Mail Server Near Youn
*  Netscape 6, Part I: Detection and Scripting
*  AOL Introduces Mobile Communicator
*  NetMenu2
*  Bluetooth Security
*  DHTML Hiermenus 4.0: The Page-Specific Parameters
*  XML Content Syndication: Part 2
*  HardwareCentral Update: Intel's Pentium 4, a New Architecture Unveiled




Copyright 2002 Jupitermedia Corporation, All Rights Reserved.
Legal Notices | Licensing, Reprints, & Permissions | Privacy Policy | Advertising on Intranet Journal
Home | eXchange | F A Q | Find | Register |