Filoweb.it

Calendario con giorno selezionabile


FB TW G+ whatsapp RSS FEED News letter
ASP
Calendario con giorno selezionabile


  <% @Language=" vbscript"  %>
<%
  
  '  force declaration of all variables
  Option Explicit
  
  Dim intYear, intMonth, intDay
  Dim intNumberOfDays, strDaysInMonths
  Dim strDate, strMonthName
  Dim strStyle, strTitle
  Dim strMethod, strURL  
  Dim strFirstDay, strLastDay, strCurrentDay
  Dim dtmPrev, dtmNext
  Dim X,Y,Z
  
  '  find out the URL of the page and the HTTP method used
  strMethod = UCase(Request.ServerVariables(" REQUEST_METHOD" ))
  strURL = LCase(Request.ServerVariables(" URL" ))
  
  '  if it' s a GET then it' s a regular browser request
  If strMethod=" GET"  Then
  
    '  use today' s date
    intDay   = CInt(Day(Date()))
    intMonth = CInt(Month(Date()))
    intYear  = CInt(Year(Date()))
    
    strFirstDay = CStr(intMonth) & " -1-"  & CStr(intYear)
    strDate  = CStr(intMonth) & " -"  & CStr(intDay) & " -"  & CStr(intYear)
    
  '  if it' s a POST then it' s a specific request
  Else
    
    '  get the submitted date
    intDay   = CInt(Day(Date()))
    intMonth = CInt(Request.Form(" txtMonth" ))
    intYear  = CInt(Request.Form(" txtYear" ))
    
    strFirstDay = CStr(intMonth) & " -1-"  & CStr(intYear)
    strDate     = strFirstDay
    
  End If
  
  '  is a date in a leap year?
  Function IsLeapYearDate(dtmTestDate)
    IsLeapYearDate = False
    If IsDate(dtmTestDate) Then
      Dim dtmTempDate
      dtmTempDate = " 1/31/"  & Year(dtmTestDate)
      dtmTempDate = DateAdd(" m" , 1, dtmTempDate)
      If Day(dtmTempDate) = 29 Then IsLeapYearDate = True
    End If
  End Function

  '  create string of days in months
  If IsLeapYearDate(" 1/1/"  & intYear) Then      
    strDaysInMonths = " 312931303130313130313031" 
  Else
    strDaysInMonths = " 312831303130313130313031" 
  End If
  
  '  get some date stuff
  strMonthName    = CStr(MonthName(intMonth))
  intNumberOfDays = CInt(Mid(strDaysInMonths,((intMonth-1)*2)+1,2))
  strLastDay      = CStr(intMonth) & " -"  & intNumberOfDays & " -"  & CStr(intYear)
  
  '  build the page title
  strTitle = " Calendar for "  & strMonthName & "  "  & intYear

  '  get the next and previous months for the menus
  dtmPrev = CDate(DateAdd(" m" , -1, strDate))
  dtmNext = CDate(DateAdd(" m" ,  1, strDate))
  
%>
<html>
<head>
<title><%=strTitle%></title>
</head>

<body>

<h1 align=" center" ><%=strTitle%></h1>

<center>
  <table width=" 300"  border=" 0"  align=" center" >
    <tr>
      <td align=" left" >
        <form action=" <%=strURL%>"  method=" POST" >
          <input type=" hidden"  name=" txtMonth"  value=" <%=Month(dtmPrev)%>" >
          <input type=" hidden"  name=" txtYear"  value=" <%=Year(dtmPrev)%>" >
          <input type=" submit"  style=" width:150"  value="  <%=MonthName(Month(dtmPrev))%>" >
        </form>
      </td>
    <% If (intMonth <> Month(Date())) Or (intYear <> Year(Date())) Then %>
      <td align=" center" >
        <form action=" <%=strURL%>"  method=" POST" >
          <input type=" hidden"  name=" txtMonth"  value=" <%=Month(Date())%>" >
          <input type=" hidden"  name=" txtYear"  value=" <%=Year(Date())%>" >
          <input type=" submit"  style=" width:150"  value=" MESE CORRENTE" >
        </form>
      </td>
    <% End If %>
      <td align=" right" >
        <form action=" <%=strURL%>"  method=" POST" >
          <input type=" hidden"  name=" txtMonth"  value=" <%=Month(dtmNext)%>" >
          <input type=" hidden"  name=" txtYear"  value=" <%=Year(dtmNext)%>" >
          <input type=" submit"  style=" width:150"  value="  <%=MonthName(Month(dtmNext))%>" >
        </form>
      </td>
    </tr>
  </table>
</center>

<hr>

<table border=" 1"  cellpadding=" 2"  cellspacing=" 2"  width=" 300"  align=" center" >
<tr>
<%
  '  print the weekday names
  For X = 1 to 7
    Response.Write " <th width=" " 14%" " >"  & WeekdayName(X,true) & " </th>"  & vbCrLf
  Next
%>
</tr>
<tr>
<%  
  '  print empty table cells for the beginning days not in the current month
  If (Weekday(strFirstDay)-1) Then  
    For X = 1 to (Weekday(strFirstDay)-1)
      Response.Write " <td> </td>"  & vbCrLf
    Next
  End If

  ' loop per i giorni del mese
  For X = 1 to intNumberOfDays

    '  Prendo il giorno della settimana che siamo adesso
    strCurrentDay = CStr(intMonth) & " -"  & X & " -"  & CStr(intYear)
    
    
    '  Scrivo la tabella con i giorni
' controllo se un numero del giorno corrisponde a quello interessato scrivo il link altrimenti nulla
if x=6 then 
Response.Write " <td id=" " "  & X & " " "  align=" " left" "  valign=" " top" " ><a href=appuntamento.asp?id="  & x & " >" & X & " </a>"  & vbCrLf
else 
    Response.Write " <td id=" " "  & X & " " "  align=" " left" "  valign=" " top" " >" 
    Response.Write " <a name=" " "  & X & " " " >"  & X & " </a><br>"  & vbCrLf
end if




    Response.Write " </td>"  & vbCrLf

    If (Weekday(strCurrentDay) = 7) And (strCurrentDay <> strLastDay) Then
      Response.Write " </tr>"  & vbCrLf & " <tr>"  & vbCrLf
    End If

  Next

  If (7-Weekday(strLastDay)) Then  
    For X = 1 to (7-Weekday(strLastDay))
      Response.Write " <td> </td>"  & vbCrLf
    Next
  End If
%>
</tr>
</table>

<hr>
</body>
</html> 
FB TW G+ whatsapp RSS FEED News letter

filoweb.it è il sito personale di Filippo Brunelli
(c) 2017 Filippo Brunelli
Le immagini ed i testi contenuti nel sito sono di proprietà di Filippo Brunelli salvo diversamente indicato.
L'uso delle immagini e del testo è gratuito per uso personale ed è subbordinato alla citazione della fonte.
Brunelli Filippo declina ogni responsabilità per l'uso che viene fatto delle informazioni presenti nel sito.
FILOWEB.it Piccolo quaderno degli appunti. Argomento: ASP, Titolo:Calendario con giorno selezionabile. Altri script riguardano: CSS, Jscript, .net, Classic Asp, HTML, Jquery, varie, url rewrite, pagina protetta da password, ecc. Altro su https://www.filoweb.it