3

Microsoft's DateTimePicker common control shows ShortDate's according to the configured Locale settings. The customer's computer is configured with a 2-digit year ShortDateFormat (d/M/yy), so the DateTimePicker shows 2-digit years:

alt text

When the user puts focus in the year block of the datetime picker, Microsoft points out the issue, and shows the full 4-digit year:

alt text

But then the user, wanting to enter 1929 as a year, types a 2-digit year:

alt text

And then when they tab out they're confused when Windows interprets their 2-digit years as being between 1930 and 2029, and it is assumed to be 2029:

alt text

The customer has a global corporate policy in place which dictates that Windows regional settings be configured for 2-digit years.

So as a workaround i need to force every DateTimePicker control to use a custom date-format, using the handy DateTime_SetFormat macro:

DateTime_SetFormat(hwnd_DateOfEventPicker, "d/M/yyyy");

This helps, so that now the DateTimePicker now always shows a 4-digit year:

alt text

The problem is that the user can still type in an "invalid" 2-digit year:

alt text

Which Windows is still intpreting, according to the rules, as 2029:

alt text

i need the date-time picker to reject 2-digit years.

If this can't work, then i'm going to be forced to replace every DateTimePicker with 3 edit boxes:

22 6 29

Where i can color invalid numbers red, and point out the invalid data entry by the user.

How can i prevent the DateTimePicker from accept y2k bugs?

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
  • I wish all the questions here were as well thought out and organized as this one. – Ben313 Jun 22 '10 at 15:42
  • 1
    @Ben313 The downside of a thorough question is that nobody can answer them. With all the "outs", or cheats, cut off, it only leaves people knowledgeable about a pretty specific problem domain. Also, you should see the original edit - where i got to have a free rant; knowing full well that i would edit them out a minute later. – Ian Boyd Jun 22 '10 at 15:56

1 Answers1

1

If you add the DTS_APPCANPARSE window style, you can handle the WM_NOTIFY: DTN_USERSTRING message and parse the string yourself

Anders
  • 97,548
  • 12
  • 110
  • 164
  • What the...i **know** i edited your answer, adding quoted text from the MSDN documentation, and link. And i know i commented on your answer, explaining why it can't work in my case. And now the edits, and comment, are gone. And there's not even any indication that the answer was ever edited. Did SO crash and rollback? – Ian Boyd Jun 23 '10 at 11:32