DateTimePicker and Year 9999

G

Guest

Converting an old application and came accross a funny problem. Have a
subscription DB with a renewal date field. If the subscription is considered
a 'freebee', then it never has to be renewed and the renewal date is null.
Well, discovered that nullableof(Date) does not work well with the
datetimepicker nor with Crystal Reports which won't even recognize that type.
Decided to change these date to 12/31/9999 (which is close enough to never
for me :~)! But, when the datetime picker see's this value, it displays
todays date! In fact, for all dates between 1/1/9999 and 12/31/9999 it
displays todays date. I guess I can make the 'freebee' date = to 12/31/9998
(which works), but am wondering if this is a 'feature' or a 'bug'.
 
C

Cor Ligthert[MVP]

Terry,

I what is a bug, I assume that it does not fit in the long, however I assume
that as you look at it that day, then it will be fixed.

Cor
 
M

Michel Posseth [MCP]

"We" ( company i work for ) discovered a long time ago that 12/31/9998 is
the maximum size you can efectively work with in .Net icw a SQL database
but we did not see this as a problem wel at least not for us :) , so in our
production systems we use 12/31/9998 as the infinite date value .

Gues it is just the maximum value that it can hold

Michel
 
J

Jeffrey Tan[MSFT]

Hi Terry,

You'd better not hard-code this 'freebee' special case value. You may use
DateTimePicker.MaxDate to get the allowable max date of DateTimePicker.

Regarding this magic value of 12/31/9998, yes, this is by design. If you
use the Reflector to view DateTimePicker.MaxDate property source code, you
will see:

public void set_MaxDate(DateTime value)
{
if (value != this.max)
{
if (value < EffectiveMinDate(this.min))
{
throw new ArgumentOutOfRangeException("MaxDate",
SR.GetString("InvalidLowBoundArgumentEx", new object[] { "MaxDate",
FormatDateTime(value), "MinDate" }));
}
if (value > MaximumDateTime)
{
throw new ArgumentOutOfRangeException("MaxDate",
SR.GetString("DateTimePickerMaxDate", new object[] {
FormatDateTime(MaxDateTime) }));
}
this.max = value;
this.SetRange();
if (this.Value > this.max)
{
this.Value = this.max;
}
}
}
As you can see, the property is bound by the MaximumDateTime property:

public static DateTime MaximumDateTime
{
get
{
return MaxDateTime;
}
}

[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public static readonly DateTime MaxDateTime;

Finally, the MaxDateTime field is set in the DateTimePicker constructor:

static DateTimePicker()
{
DefaultTitleBackColor = SystemColors.ActiveCaption;
DefaultTitleForeColor = SystemColors.ActiveCaptionText;
DefaultMonthBackColor = SystemColors.Window;
DefaultTrailingForeColor = SystemColors.GrayText;
EVENT_FORMATCHANGED = new object();
MinDateTime = new DateTime(0x6d9, 1, 1);
MaxDateTime = new DateTime(0x270e, 12, 0x1f);
}

0x270e is just 9998 and 0x1f is 31. So the MaxDateTime field is initialized
to 12/31/9998 in the constructor code.

Anyway, we may use DateTimePicker.MaxDate to determine the max allowed date
without hard-code it. Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Hi Jeffery,
So, are you suggesting that I leave the database value as Null and then
map it to the DateTimePicker.Max and back on the binding's format and parse
events? Else, if I replace the DB values, it is by definition hardcoded and
any future change to the DateTimePicker max value would lead to other
problems.
--
Terry


"Jeffrey Tan[MSFT]" said:
Hi Terry,

You'd better not hard-code this 'freebee' special case value. You may use
DateTimePicker.MaxDate to get the allowable max date of DateTimePicker.

Regarding this magic value of 12/31/9998, yes, this is by design. If you
use the Reflector to view DateTimePicker.MaxDate property source code, you
will see:

public void set_MaxDate(DateTime value)
{
if (value != this.max)
{
if (value < EffectiveMinDate(this.min))
{
throw new ArgumentOutOfRangeException("MaxDate",
SR.GetString("InvalidLowBoundArgumentEx", new object[] { "MaxDate",
FormatDateTime(value), "MinDate" }));
}
if (value > MaximumDateTime)
{
throw new ArgumentOutOfRangeException("MaxDate",
SR.GetString("DateTimePickerMaxDate", new object[] {
FormatDateTime(MaxDateTime) }));
}
this.max = value;
this.SetRange();
if (this.Value > this.max)
{
this.Value = this.max;
}
}
}
As you can see, the property is bound by the MaximumDateTime property:

public static DateTime MaximumDateTime
{
get
{
return MaxDateTime;
}
}

[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public static readonly DateTime MaxDateTime;

Finally, the MaxDateTime field is set in the DateTimePicker constructor:

static DateTimePicker()
{
DefaultTitleBackColor = SystemColors.ActiveCaption;
DefaultTitleForeColor = SystemColors.ActiveCaptionText;
DefaultMonthBackColor = SystemColors.Window;
DefaultTrailingForeColor = SystemColors.GrayText;
EVENT_FORMATCHANGED = new object();
MinDateTime = new DateTime(0x6d9, 1, 1);
MaxDateTime = new DateTime(0x270e, 12, 0x1f);
}

0x270e is just 9998 and 0x1f is 31. So the MaxDateTime field is initialized
to 12/31/9998 in the constructor code.

Anyway, we may use DateTimePicker.MaxDate to determine the max allowed date
without hard-code it. Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi Terry,

Yes, formatting and parsing between DateTimePicker.MaxDate and DBNull value
is what I mean. This is because the default DateTimePicker does not support
null value.

Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top