Skip to content

UltraDateTimeEditor and MaxDate

New Discussion
Mark
Mark asked on May 27, 2010 3:18 PM

Can anyone explain why although the MaxDate property is a DateTime you cannot set it to DateTime.MaxValue.

 i.e. myDateEditor.MaxDate = DateTime.MaxValue;   causes an exception.

I had a look with reflector, on the set of the property a comparation is made to a private static variable called "defaultMaxDate", if the value is greater than defaultMaxDate the out of range exception is thrown. It appears the value of defaultMaxDate is 31/12/998 (DateTime.MaxValue is 31/12/999).

Im just a bit confused as to what purpose this serves ?

Thanks

Sign In to post a reply

Replies

  • 0
    Mike Saltzman
    Mike Saltzman answered on Oct 2, 2008 5:02 PM

     Hi Mark,

    I took a look and found some notes from the developers about why we do this: 

            //    Note that we do this because for some reason the static
            //    DateTime.MinValue property doesn't show up in the VB property grid (???), and
            //    MaxValue shows up, but with the time portion (11:59)
            //
            //    Furthermore, the static DateTime.MaxValue is 12/31/9999, and the default MaxDate
            //    for the MonthCalendar control (which is used both by the DateTimeEditor and the VB
            //    property grid) is 12/31/9998

    • 0
      Markus Accola
      Markus Accola answered on May 27, 2010 8:09 AM

      Hi Mike,

      If I add a new datarow to my dataset I initialize my dateFrom to TODAY and my dateTo to DateTime.MaxValue. Bound this fields to DateTimeEditor looks as expected: the dateTo Field is empty because the Date is not valid that means my daterange is 'open' to the end.

      But on validating, I see that the date from the editor is set to somewhat 01.01.0001. Setting the value to the maxDate the control can handle, but it is displayed by the control.

      How initialize a open date range from today forward ? How to prevent displaying min- and max-dates?

      Regards. Markus

      • 0
        Mike Saltzman
        Mike Saltzman answered on May 27, 2010 2:52 PM

        What kind of data source are you using?

        It sounds to me like the best thing to do would be to make your date fields allow nulls and use Null instead of MinDate/MaxDate.

      • 0
        Markus Accola
        Markus Accola answered on May 27, 2010 3:18 PM

        Hi Mike,

        that is exactly I decided to do. I changed my underlying data table (and database) to allow NULL. The editor display text is empty if the value is NULL.

        The reason why I did not allowed NULL so far is not to care about open date intervalls and validating data etc.. Would be easier to deal always with full defined date ranges.

        Thanks for answer.

        Markus

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Mark
Favorites
0
Replies
4
Created On
May 27, 2010
Last Post
16 years, 4 months ago

Suggested Discussions

Tags

No tags

Created by

Created on

May 27, 2010 3:18 PM

Last activity on

May 27, 2010 3:18 PM