in

dotNetFreak

Ramblings & Controls from a .NET Addicted Freak!

Kevin Gearing's Blog

DateTimePicker Problems

I've just stumbled across a couple of great problems with the default WinForms DateTimePicker control:

Within an application I'm building I need to be able to represent a NullDate. Previously I've always used Date.MinValue to indicate whether or not a date has been specifyed, but after data binding a date property to the DateTimePicker I suddenly found out that Date.MinValue = 00:00:00 01/01/0001, and the DateTimePicker only supports dates after 00:00:00 01/01/1753.

Fair enough I thought I can understand the logic in that (kind of), so I created a constant within my application called 'NullDate' that returns 00:00:00 01/01/1800, which whilst it isn't ideal, does solve the problem.

But now I have the problem that the DateTimePicker (even though it's being fed a 4 digit year), believes that 00:00:00 01/01/1800 actually equals 00:00:00 01/01/2000. Argh! Now I need to figure out why! I could understand it if I was passing in a 2 digit date, but not a 4 digit one.

I'll update this post if/when I find a solution.

UPDATE:

Right it looks like it's to do with the property being databound to an object. If I set the 'Value' or 'Text' property manually it displays the correct date, however when an object is databound to the 'Text' property it shows the wrong century. I'm guessing that the DateTimePicker is performing Property.ToString() to get the value from the object rather than Property.ToString(CustomFormat), i.e. Property.ToString("dd/MM/yyyy").

RESOLVED:

Change the 'Short Date' settings on the machine to dd/MM/yyyy instead of the UK default of dd/MM/yy.

Comments

 

Aaron Gusman said:

dateTimePicker should let you select a date before 1753 for flexibility in my opinion.  I think that the mathematics behind  calculating dates remains the same even for years before 1753 so I do not understand why there is this limitation in place.  Anywayz I might be wrong.

December 14, 2007 11:15 AM
 

Sameer Pathan said:

Dear,

  Still problem exists.....

any solution pls update this section

Reagrds,

Sameer Pathan

March 18, 2008 7:29 AM
 

pulpoko said:

try this:

controlpanel/Regional and Language Options /Customize/Date:

CHANGE Short Date format :   d/M/aaaa     works!  

( d/M/aa  NO !!!)

www.experts-exchange.com/.../Short-Date-Format.gif

October 3, 2008 10:30 AM

Leave a Comment

(required)  
(optional)
(required)  

Protected by FormShield
Refresh
Listen
Please enter the characters shown on the image


Code:


Add
Copyright ©2004-2007 Kevin Gearing. All Rights Reserved.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems