Question

I am using datetimepicker which displays the date(which is retrieved from the database). I have run my application on a few machines and I have found that on Windows XP SP2, the max date that can be retrieved and displayed is 2020, but for later versions of the OS the max date can be highier, e.g. 2999. Does anyone know about this issue?

Thank you for your help. Jing Jing

Was it helpful?

Solution

You can use the DateTime.MaxValue property to retrieve the largest possible date, dependent on the system. If you are having problems reading dates due to overflow, you can use the DateTime.TryParse() methods to attempt a read of the value without throwing an exception.

UPDATE: Martinho is correct. From MSDN:

Some calendars, such as the UmAlQuraCalendar, support an upper date range that is earlier than MaxValue. In these cases, trying to access MaxValue in variable assignments or formatting and parsing operations can throw an ArgumentOutOfRangeException. Rather than retrieving the value of DateTime.MaxValue, you can retrieve the value of the specified culture's latest valid date value from the System.Globalization.CultureInfo.DateTimeFormat.Calendar.MaxSupportedDateTime property.

So, use the System.Globalization.CultureInfo.DateTimeFormat.Calendar.MaxSupportedDateTime field to get the maximum date value supported by the system.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top