ASP code for library hours

December 20, 2007

Today I spent most of my day writing an ASP code from scratch that will display our hours based on the date. While this sounds simple, here are the steps I followed:

  • Set a variable today as Date()
  • Declare the base rule for the three days we have the same hours.
  • Set exceptions by day of the week above that
  • Set our closed for the holiday dates above the standard hours
  • Set our finals hours above those

Since ASP executes in a logical “If..Elseif…Else..End if” statement, this works. However, I then realized one fact: we’re open past midnight at times. I don’t want the next days hours to start until 1:00am. A quick chat with our campus ASP person to figure out what to do and some creative errors (don’t we learn best by errors?) I was able to declare the following statement:

If Time() < “01:01 AM” then
today = DateAdd(“d”,-1,today)

Update:

Dim miltime
miltime = FormatDateTime(today,4)
If miltime < “01:01:00″ Then
today = DateAdd(“d”,-1,today)

This says that if it’s before 1:01am, then subtract one day from the date, effectively turning back time.

Easy enough, eh? Well, I decided I didn’t like the standard time display “Wednesday, December 19, 2007.” So, I used some more ASP to break it apart and display the Month, Day and a new variable called ord which stands for the ordinal number contraction (st, nd, rd, th). I threw that in an If..Then statement right after the time statement but before the hours designation. All in all, it worked out.

Bottom line: Email me if you want the code: libguy@libguy.info.