Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old March 23rd, 2006, 12:50 PM
Registered User
Join Date: Mar 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default inconsistent date formats from calendar control

I am getting inconsistent date formats from the ASP.Net calendar control. Sometimes when I click the button I get "3/30/2006 12:00:00 AM" sometimes I get "30/03/2006 00:00:00". This is breaking my code. I have reproduced the problem in the code below (this demonstrates the problem it is not the code I want to use in real life). It does not occur on my development machine just on the production server.

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="testdate.aspx.vb" Inherits="WebApplication1.testdate"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
        <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
        <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
        <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    <body MS_POSITIONING="GridLayout">
        <form id="Form1" method="post" runat="server">
            <asp:Calendar id="TestVisitDate" runat="server" BorderColor="Blue" FirstDayOfWeek="Monday">
                <SelectorStyle BackColor="#C0C0FF"></SelectorStyle>
                <DayStyle BackColor="White"></DayStyle>
                <NextPrevStyle BackColor="#C0C0FF"></NextPrevStyle>
                <DayHeaderStyle ForeColor="White" BackColor="CornflowerBlue"></DayHeaderStyle>
                <SelectedDayStyle BackColor="#FFFF80"></SelectedDayStyle>
                <TitleStyle BackColor="#C0C0FF"></TitleStyle>
                <OtherMonthDayStyle BackColor="#E0E0E0"></OtherMonthDayStyle>
            <asp:Button id="Button1" onclick="setdates" runat="server" text="Search By Date"></asp:Button>
            <asp:Label id="VisitDate_Label" runat="server" Visible="True" />

Public Class testdate
    Inherits System.Web.UI.Page
    Dim VisitDate_value
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    Protected WithEvents VisitDate_Label As System.Web.UI.WebControls.Label
    Protected WithEvents TestVisitDate As System.Web.UI.WebControls.Calendar

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
    End Sub
    Sub setdates(ByVal Sender As Object, ByVal E As EventArgs)

        VisitDate_Label.Text = TestVisitDate.SelectedDate.ToString()

    End Sub

End Class

Old March 23rd, 2006, 03:07 PM
Friend of Wrox
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts

Hi Sheridan,

Ran your code on my server and could not get the foul date formats that you are getting.

I'm using the ASP:Calendar control in many places in one app I'm doing and it has never gotten any other format than "mm/dd/yyyy". I am using it in a search function as well but I never search with the long date format. I don't know if that's critical to your app or not.

I use "calDate.SelectedDate.ToShortDateString" and write that date to a form textbox that then gets posted.

So far your code is working on your box and mine (Server 2000) but not on your production server. Sounds like it could be something whacky on the server but you probably already know that.

Wish I was of more help.

Good luck.

Old March 24th, 2006, 05:56 AM
Registered User
Join Date: Mar 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks Richard
With your help I have fixed the problem.
I am using VisitDate.SelectedDate.ToLongDateString() which gives me a consistent date in a format I can use without changing lots of code.
I think I have also found out why it only happens on the production server and that is because there is an old version of the .net framework installed on the server. My development machine has a newer version and I do not get the problem.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Date Formats carumuga SQL Server 2000 4 January 2nd, 2007 07:20 PM
XML Date Formats tracyamgray XSLT 5 July 12th, 2006 10:17 PM
Calendar Control 9 .. separating date vars Chantale Access VBA 2 December 2nd, 2004 03:57 PM
SQL and Date Formats al_bllinky Access 3 August 28th, 2003 08:45 AM
Date formats in the forum Crispin Horsfield Forum and Wrox.com Feedback 1 August 3rd, 2003 08:14 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.