简体   繁体   中英

ASP.net webforms DateTime format issue on change of web server

My application written in ASP.NET webforms was working fine on web server, but after hosting company changes the server, on new server its getting datetime errors, is there any way to write server agnostic universal datetime code in ASP.NET?

My code is as follows: I fetch financial year date range as follows

if (rd["StartDate"] == DBNull.Value)
{
    this.StartDate = new DateTime();
}
else
{
    this.StartDate = Convert.ToDateTime(rd["StartDate"]);
}

if (rd["EndDate"] == DBNull.Value)
{
    this.EndDate = new DateTime();
}
else
{
    this.EndDate = Convert.ToDateTime(rd["EndDate"]);
}

Then in webforms, I compare it with user inputs bill date

if (!DateTime.TryParse(txtbilldate.Text, cul, DateTimeStyles.None, out billdate))
{
    ucMessage.Visible = true;
    ucMessage.ShowErrorMsg("Invalid bill Date");
    txtbilldate.Focus();
    return;
}

It was working fine, now on new server it is not working anymore

Hum, you don't show what this.StartDate is???

should you not be using this:

 this.StartDate = DateTime.Today;

The above of course does not include the time portion (which I assume you don't want a time part, but just a date part).

so say this:

        DateTime dt1 = DateTime.Today;
        DateTime dt2 = DateTime.Now;

        Debug.Print(dt1.ToString());
        Debug.Print(dt2.ToString());

Output:

1/3/2023 12:00:00 AM
1/3/2023 10:14:07 PM

So, my guess here (and I stress "guess"), is this assigment:

this.StartDate = new DateTime();

Should not that be:

DateTime StartDate;  // defined at page class level???

this.StartDate = DateTime.Today;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM