[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 430
  • Last Modified:

Short Date Format bug 2050 changes to 1950

In the regional settings, the Short Date Format is set to d-M-yy. I assume any setting with 2 figures for the date will give this bug.
"When a 2 digit year is entered interpret it as a year" between 1930 and 2029.
So if I enter 50 it should see it as 1950. If I enter 20 it should see it as 2020.

I have a dateTimePicker control on my form with a 4 digit year setting.
I set it to custom yyyy-MM-dd to be exact.

When I enter 2050 and go to the next control it keeps 2050 as the year.

Now I bind the control using the code below.
Now when I enter 2050 and go to the next control it changes the date to 1950!!!

My actual code uses binding to a SQL-server datatable and gives the same bug.
But this is easier to reproduce.
Bug found in Windows 2000 and XP professional using VS 2005, .NET 2.0.

Does anyone know a solution to this bug, other then changing the regional settings or not using databinding of course.



  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim dt As DateTime = New DateTime()
    Dim values As Object() = {#11/18/1970#} ' any random date

    If m_dataTable Is Nothing Then
      m_dataTable = New DataTable
      m_dataTable.Columns.Add("date1", dt.GetType)
      m_dataTable.Rows.Add(values)
      DateTimePicker1.DataBindings.Add("Text", m_dataTable, "date1")
    End If
  End Sub
0
NicoLaan
Asked:
NicoLaan
1 Solution
 
NicoLaanAuthor Commented:
Solved the bug.
Why didn't I see this before!!

Changed binding from Text to Value
DateTimePicker1.DataBindings.Add("Value", m_dataTable, "date1")

Now it works.
0
 
GranModCommented:
Closed, 500 points refunded.
GranMod
The Experts Exchange
Community Support Moderator of all Ages
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now