ASP + Format Dates from Database

Discussion in 'ASP General' started by Vincent Jones, Dec 21, 2003.

  1. I already have a calendar from VBScript but I need it to bold on the
    dates when there is an event. I've created the Database connection
    but I can't seem to figure out how to integrate the two.

    I HAVE TO FIGURE OUT HOW TO ADD THE DATBASE CONNECTION
    -----
    <%
    R.Open strMonth, obConn, 3,3,1
    Do While Not R.EOF

    R.MoveNext
    Loop
    R.Close
    Set R = Nothing
    %>
    ----


    TO THE CALENDAR
    -----

    <TABLE width="160" height="64" BORDER=1 CELLPADDING=1 cellspacing="0"
    bordercolor="#666666" bgcolor="#CCCC99">
    <TR>
    <TD height="50">

    <%
    Function GetDaysInMonth(iMonth, iYear)
    Dim dTemp
    dTemp = DateAdd("d", -1, DateSerial(iYear, iMonth + 1, 1))
    GetDaysInMonth = Day(dTemp)
    End Function
    Function GetWeekdayMonthStartsOn(dAnyDayInTheMonth)
    Dim dTemp
    dTemp = DateAdd("d", -(Day(dAnyDayInTheMonth) - 1),
    dAnyDayInTheMonth)
    GetWeekdayMonthStartsOn = WeekDay(dTemp)
    End Function

    Function SubtractOneMonth(dDate)
    SubtractOneMonth = DateAdd("m", -1, dDate)
    End Function

    Function AddOneMonth(dDate)
    AddOneMonth = DateAdd("m", 1, dDate)
    End Function

    Dim dDate ' Date we're displaying calendar for
    Dim iDIM ' Days In Month
    Dim iDOW ' Day Of Week that month starts on
    Dim iCurrent ' Variable we use to hold current day of month as we
    write table
    Dim iPosition ' Variable we use to hold current position in table


    'Database connection
    Dim objConn, strQuery, RS
    Dim obConn, strMonth, R
    Dim strConnection
    Dim stConnection
    Dim dtDateEv

    dtDateEv = CDate(Request.QueryString("date"))

    Set objConn = Server.CreateObject("ADODB.Connection")
    Set obConn = Server.CreateObject("ADODB.Connection")

    strConnection = "DSN=SERF;Database=PMA;"
    strConnection = strConnection & "UID=sa;PWD=;"

    stConnection = "DSN=SERF;Database=PMA;"
    stConnection = stConnection & "UID=sa;PWD=;"

    objConn.Open strConnection
    obConn.Open stConnection

    Set RS = Server.CreateObject("ADODB.Recordset")
    Set R = Server.CreateObject("ADODB.Recordset")

    If Request.QueryString("date") <> "" Then
    strQuery = "Select * from ptbSpecialEvent Where EventDate=#" &
    dtDateEv & "# Order By EventDate"
    strMonth = "Select EventDate from ptbSpecialEvent"
    Else
    strQuery = "Select * from ptbSpecialEvent"
    End IF

    If IsDate(Request.QueryString("date")) Then
    dDate = CDate(Request.QueryString("date"))
    Else
    If IsDate(Request.QueryString("month") & "-" &
    Request.QueryString("day") & "-" & Request.QueryString("year")) Then
    dDate = CDate(Request.QueryString("month") & "-" &
    Request.QueryString("day") & "-" & Request.QueryString("year"))
    Else
    dDate = Date()

    If Len(Request.QueryString("month")) <> 0 Or
    Len(Request.QueryString("day")) <> 0 Or
    Len(Request.QueryString("year")) <> 0 Or
    Len(Request.QueryString("date")) <> 0 Then
    Response.Write "The date you picked was not a valid date. The
    calendar was set to today's date.<BR><BR>"
    End If

    End If
    End If

    iDIM = GetDaysInMonth(Month(dDate), Year(dDate))
    iDOW = GetWeekdayMonthStartsOn(dDate)

    %>
    <STYLE>
    A {
    text-decoration: none;
    color: black
    }
    </STYLE>
    <TABLE width="100%" CELLPADDING=1 CELLSPACING=0>
    <TR>
    <TD ALIGN="center" COLSPAN=7>
    <TABLE WIDTH=100% BORDER=0 CELLSPACING=0
    CELLPADDING=0>
    <TR>
    <TD width="5%" ALIGN="right"><A
    HREF="file:///D|/wwwroot1/test/index.asp?date=<%=
    SubtractOneMonth(dDate) %>"><img
    src="file:///C|/Inetpub/wwwroot/arrow_month_nav_left.gif" width="8"
    height="8" border="0"></A></TD>
    <TD width="90%" ALIGN="center"><B><%=
    MonthName(Month(dDate)) & " " & Year(dDate) %></B></TD>
    <TD width="5%" ALIGN="left"><A
    HREF="file:///D|/wwwroot1/test/index.asp?date=<%= AddOneMonth(dDate)
    %>"><img src="file:///C|/Inetpub/wwwroot/arrow_month_nav.gif"
    width="8" height="8" border="0"></A></TD>
    </TR>
    </TABLE>
    </TD>
    </TR>
    <TR>
    <TD height="23" ALIGN="center">S</TD>
    <TD ALIGN="center">M</TD>
    <TD ALIGN="center">T</TD>
    <TD ALIGN="center">W</TD>
    <TD ALIGN="center">T</TD>
    <TD ALIGN="center">F</TD>
    <TD ALIGN="center">S</TD>
    </TR>
    <%

    If iDOW <> 1 Then
    Response.Write vbTab & "<TR>" & vbCrLf
    iPosition = 1
    Do While iPosition < iDOW
    Response.Write vbTab & vbTab & "<TD>&nbsp;</TD>" & vbCrLf
    iPosition = iPosition + 1
    Loop
    End If

    R.Open strMonth, obConn

    iCurrent = 1
    iPosition = iDOW
    Do While iCurrent <= iDIM

    If iPosition = 1 Then
    Response.Write vbTab & "<TR>" & vbCrLf
    End If

    Do While Not R.EOF
    Response.Write vbTab & vbTab & "<TD align=center><A
    HREF=""index.asp?date=" & Month(dDate) & "-" & iCurrent & "-" &
    Year(dDate) & """>" & iCurrent & "</A></TD>" & vbCrLf

    Loop

    If iPosition = 7 Then
    Response.Write vbTab & "</TR>" & vbCrLf
    iPosition = 0
    End If

    iCurrent = iCurrent + 1
    iPosition = iPosition + 1
    Loop

    R.Close
    Set R = Nothing

    If iPosition <> 1 Then
    Do While iPosition <= 7
    Response.Write vbTab & vbTab & "<TD>&nbsp;</TD>" & vbCrLf
    iPosition = iPosition + 1
    Loop
    Response.Write vbTab & "</TR>" & vbCrLf
    End If
    %>
    </TABLE>
    </TD>
    </TR>
    </TABLE>
    ----
     
    Vincent Jones, Dec 21, 2003
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kenneth
    Replies:
    2
    Views:
    14,102
    Kenneth
    Jan 14, 2004
  2. Rookie Card
    Replies:
    1
    Views:
    1,654
    Daniel Fisher\(lennybacon\)
    Aug 5, 2005
  3. David Lozzi

    Dates dates dates dates... SQL and ASP.NET

    David Lozzi, Sep 29, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,075
    Rob Schieber
    Sep 30, 2005
  4. Chu
    Replies:
    3
    Views:
    4,476
    Shawn
    Aug 15, 2006
  5. PW

    Dates! Dates! Dates!

    PW, Aug 7, 2004, in forum: ASP General
    Replies:
    4
    Views:
    484
    Mark Schupp
    Aug 9, 2004
  6. Replies:
    1
    Views:
    378
    Jano Svitok
    Jul 17, 2007
  7. kellygreer1

    RFC-822 dates into Ruby dates

    kellygreer1, Jun 8, 2008, in forum: Ruby
    Replies:
    1
    Views:
    459
    Eric I.
    Jun 8, 2008
  8. Dr J R Stockton

    FAQ Dates; Opera Dates.

    Dr J R Stockton, Jun 18, 2007, in forum: Javascript
    Replies:
    0
    Views:
    305
    Dr J R Stockton
    Jun 18, 2007
Loading...