CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2003
    Location
    Australia
    Posts
    137

    Calendar Date Format Issue

    I have some asp code that pops up a calendar and allows the user to scroll months, and to choose a date.

    The web form shows a start date and an end date.
    There is a submit button, that calls up a result form to show the values picked in the two date fields.

    We are on Australian DD/MM/YYYY format.

    The code runs ok on my collegue's server, but when I run it on my server (windows 2000 server) and on my laptop (XP professional) there appears to be a date format issue.

    I have checked the region settings and the custom formats (XP) on my operating systems but they were as expected.

    I believe the Dateadd function is processing dates as mm/dd/yyyy.

    Assuming the operating system dates are ok, is there a javascript / asp / IIS date format setting I should be aware of?

    To be honest I don't understand my problem, I have manipulated the code and have the calendar half working, but I don't know what I should be fixing.

    The collegue mentioned that the operating system date is all that should be set, and the programs will use it as the default format.
    I am not sure about this?

    Any advice or explanations are welcomed.
    TT

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Calendar Date Format Issue

    If the code is in ASP then this is a server-side issue not a client-side.

    Can you post your code, please?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Nov 2003
    Location
    Australia
    Posts
    137

    Re: Calendar Date Format Issue

    Peejavery thanks for your interest.

    The code is based on 5 files (2 being .gif files to show left/right arrows for calendar month scrolling).

    I will eventually embed this into a host application (Goldmine).
    At the moment I am putting the asp into my C:\inetpub\wwwroot folder and calling the asp on my browser using http://localhost/default.asp

    The default.asp file calls the cal.asp to maneuver the calendar and to select start and end dates.
    The form has a submit button, when this is clicked, the result.asp is called to show a new form with the values entered in the start/end dates.

    Default.asp
    --------------

    Code:
    <html>
    
    <head>
    <meta http-equiv="Content-Language" content="en-us">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Start Date</title>
    </head>
    
    <body>
    
    
    			<SCRIPT ID="clientEventHandlersJS" LANGUAGE="javascript">
    <!--
    
    function SD_onclick() {
    
    var URL
    URL = "cal.asp"
    URL = URL + "?date="
    URL = URL + escape(MyForm.startdate.value)
    URL = URL + "&target=startdate"   
    window.open(URL,"","scrollbars=no,status=no,width=150,height=200,dependent=yes") 
    //window.open(URL,"","") 
    }
    function ED_onclick() {
    var URL
    URL = "cal.asp"
    URL = URL + "?date="
    URL = URL + escape(MyForm.enddate.value)
    URL = URL + "&target=enddate"   
    window.open(URL,"","scrollbars=no,status=no,width=150,height=200") 
    
    }
    
    //-->
    
    			</SCRIPT>
    
    
    
    <form method="GET" name="MyForm" action="result.asp">
    	
    	<table border="0" width="55%" id="table1">
    		<tr>
    			<td width="104"><font size="1" face="Arial">Start Date</font></td>
    			<td><input type="text" name="startdate" size="20"><input type="button" value=".." name="SD" LANGUAGE="javascript" onclick="return SD_onclick()"></td>
    		</tr>
    		<tr>
    			<td width="104"><font size="1" face="Arial">End Date</font></td>
    			<td><input type="text" name="enddate" size="20"><input type="button" value=".." name="ED" LANGUAGE="javascript" onclick="return ED_onclick()"></td>
    		</tr>
    		<tr>
    			<td width="104">&nbsp;<%="ASP IS Working"%></td>
    			<td><input type="submit" value="Submit" name="B1"></td>
    		</tr>
    	</table>
    
    </form>
    
    </body>
    
    </html>

    Cal.asp
    ---------

    Code:
    <html>
    
    <head>
    <meta http-equiv="Content-Language" content="en-us">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <meta name="GENERATOR" content="Microsoft FrontPage 6.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>Select Date</title>
    <style>
    <!-- A { text-decoration: none; color: rgb(0,0,128); font-family: Verdana, Arial; font-style: normal; font-variant: normal; } -->
    </style>
    <style fprolloverstyle>A:hover {color: #FFFF66; font-weight: bold}
    </style>
    </head>
    
    <body topmargin="0" leftmargin="0">
    
    <%
    
    if Request.QueryString("Target")<> "" then
    		
    	if Request.QueryString("Target") = "startdate" then
    		Session("Cal") = "StartDate"
    	else	
    		Session("Cal") = "EndDate"
    	end if
    else
    		
    end if
    if Session("Cal") = "StartDate" then %>
    
    <script>
    function Control(action){
    opener.document.MyForm.startdate.value=action
    close();
    }
    
    </script>
    
    
    <% else %>
    
    <script>
    function Control(action){
    opener.document.MyForm.enddate.value=action
    close();
    }
    
    </script>
    
    <% end if %>
    
    <% 
    dim Respond(50)
    if isdate(Request.QueryString("Date")) then
    	mth = month(Request.QueryString("Date"))
    	yr = year(Request.QueryString("Date"))
    	Input_Date = Request.QueryString("Date")
    
    end if 
    
    If Mth = 0 Then
        Mth = Month(Now)
    	Yr = Year(now)
    	Input_Date = "1/" & mth & "/" & year(now)
    End If
    
    '// set date to the first of the month
    dtx = CDate("1/" & Mth & "/" & Yr)
    '// work out first weekday
    Ds = Weekday(dtx,2) - 1
    
    For a = 0 To 30
        x = DateAdd("d", a, dtx)
        If DateDiff("m", dtx, x) = 0 Then
        Respond(Ds) = x
        
        End If
        Ds = Ds + 1
    Next
    
    %>
    
    
    
    <table border="0" width="100%" height="50">
      <tr>
        <td width="100%" height="19" colspan="7" align="center"><font face="Verdana" size="1">
          <table border="0" width="100%">
            <tr>
              <td width="11%"><a href="cal.asp?date=<%=dateadd("m",-1,Input_Date)%>"><img border="0" src="Aleft.gif"></a></td>
            </font>
              <td width="81%" valign="middle" align="center"><font face="Verdana" size="1">
          <%=monthname(mth) & " " & yr%></font></td>
              <td width="8%" valign="middle" align="right"><a href="cal.asp?date=<%=dateadd("m",1,Input_Date)%>"><img border="0" src="aRight.gif"></a></td>
            </tr>
          </table>
          </td>
      </tr>
      <tr>
        <td width="14%" height="19" align="center" bgcolor="#D7E4E8"><font face="Verdana" size="1">M</font></td>
        <td width="14%" height="19" align="center" bgcolor="#D7E4E8"><font face="Verdana" size="1">T</font></td>
        <td width="14%" height="19" align="center" bgcolor="#D7E4E8"><font face="Verdana" size="1">W</font></td>
        <td width="14%" height="19" align="center" bgcolor="#D7E4E8"><font face="Verdana" size="1">T</font></td>
        <td width="14%" height="19" align="center" bgcolor="#D7E4E8"><font face="Verdana" size="1">F</font></td>
        <td width="15%" height="19" align="center" bgcolor="#D7E4E8"><font face="Verdana" size="1">S</font></td>
        <td width="15%" height="19" align="center" bgcolor="#D7E4E8"><font face="Verdana" size="1">S</font></td>
      </tr>
     <% 
     DS = 0
     for a = 1 to 6 %>
      <tr>
        <td width="14%" height="19" valign="middle" align="center" bgcolor="#E4E4E4"><font face="Verdana" size="1"><a href="#" onclick="Control('<%=Respond(ds)%>')"><%=Calday(Respond(ds))%></a></font></td>
        <td width="14%" height="19" valign="middle" align="center" bgcolor="#E4E4E4"><font face="Verdana" size="1"><a href="#" onclick="Control('<%=Respond(ds+1)%>')"><%=Calday(Respond(ds+1))%></a></font></td>
        <td width="14%" height="19" valign="middle" align="center" bgcolor="#E4E4E4"><font face="Verdana" size="1"><a href="#" onclick="Control('<%=Respond(ds+2)%>')"><%=Calday(Respond(ds+2))%></a></font></td>
        <td width="14%" height="19" valign="middle" align="center" bgcolor="#E4E4E4"><font face="Verdana" size="1"><a href="#" onclick="Control('<%=Respond(ds+3)%>')"><%=Calday(Respond(ds+3))%></a></font></td>
        <td width="14%" height="19" valign="middle" align="center" bgcolor="#E4E4E4"><font face="Verdana" size="1"><a href="#" onclick="Control('<%=Respond(ds+4)%>')"><%=Calday(Respond(ds+4))%></a></font></td>
        <td width="15%" height="19" valign="middle" align="center" bgcolor="#E4E4E4"><font face="Verdana" size="1"><a href="#" onclick="Control('<%=Respond(ds+5)%>')"><%=Calday(Respond(ds+5))%></a></font></td>
        <td width="15%" height="19" valign="middle" align="center" bgcolor="#E4E4E4"><font face="Verdana" size="1"><a href="#" onclick="Control('<%=Respond(ds+6)%>')"><%=Calday(Respond(ds+6))%></a></font></td>
      </tr>
     <% 
     ds = ds + 7
     next 
      %>
    </table>
    
    
    
    <% function CalDay(dte)
    
    if isdate(dte) then
    	Calday = day(dte) 
    	 if datediff("d",now(),dte) = 0 then
    		Calday = "<B><font color='#FF0000'>" & day(dte) & "</B>"
    	 else
    		if isdate(Request.QueryString("Date")) then 
    			if datediff("d",Request.QueryString("Date"),dte) = 0 then
    				'Calday = "<B>" & day(dte) & "</B>"
    			end if
    		end if
    	 end if
    else
    	Calday = "&nbsp;"
    end if
    
    end function
    %>

    Result.asp
    -------------

    Code:
    <%@ Language=VBScript %>
    <html>
    <head>
    <meta name="GENERATOR" Content="Microsoft Visual Studio.NET 7.0">
    </head>
    <body>
    <%
    
    
    Response.Write "You said the start date was " & request.QueryString("StartDate") & "<BR>"
    response.Write "You Said the end date was " & request.QueryString("Enddate")& "<BR>"
    response.Write "Your Browser sends the following " & Request.ServerVariables("HTTP_USER_AGENT") 
     
     
    
    %>
    
    
    </body>
    </html>
    TT

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: Calendar Date Format Issue

    Quote Originally Posted by T2T2
    Peejavery thanks for your interest.
    Well, I am actually a PHP guy when it comes to server-side scripting. We do have some good programmers that would probably be able to solve your problem.

    The problem at hand is that you accidentally posted in the wrong forum. This should be in server-side scripting but it is currently in client-side. I will get a moderator to move it there for you. Your chances of getting this answered to your liking will more than double.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Nov 2003
    Location
    Australia
    Posts
    137

    Re: Calendar Date Format Issue

    Sorry and thanks for the help.

    I guess that exposes me as a newbee web programmer.
    TT

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: Calendar Date Format Issue

    Quote Originally Posted by T2T2
    I guess that exposes me as a newbee web programmer.
    Eh, don't think anything of that.

    Can you clarify one thing for me, please? Did you say that it worked on your friends computer but not on yours? If this is the case it might be totally not related to the actual scripts but variants on the server computers.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  7. #7
    Join Date
    Nov 2003
    Location
    Australia
    Posts
    137

    Re: Calendar Date Format Issue

    Yes, this code was written by a collegue and forwarded to myself.
    I tested the code on his server (sydney australia) and it worked perfectly.
    Unfortunately, here in Melbourne the server and my laptop did not behave the same.

    I checked the region settings and the default date formats on my machines and could not see anything that could explain the error.
    I am assuming that date formatting differences in the server components would explain the situation.

    My collegue mentioned that manipulating operating system dates does not always give the correct results? Both my server and my laptop where set up with Australian default formats to begin with, so I did not change settings.

    I have manipulated the code some what , and almost got it to perform.
    If I pick a date on the calendar that has a day value 12 or less, the calendar misbehaves. Clicking on the arrows to change month I get month scrolling going back to 1899, or the month scroll follows the day value rather than the month value (suggesting I have a mm/dd/yy format happening).
    When I select a day above the 12th the calendar scrolls months correctly.

    Basically, I converted the date to mm/dd/yy before using functions the Dateadd .

    If you know of server side components I should be checking please let me know.
    TT

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured