C# DateTime MaxValue
Description
DateTime MaxValue
represents the largest possible value
of DateTime. This field is read-only.
Syntax
DateTime.MaxValue
has the following syntax.
public static readonly DateTime MaxValue
Example
The following example shows how to use the largest possible value of DateTime.
using System;/* w ww. jav a 2 s .com*/
public class MainClass{
public static void Main(String[] argv){
long numberOfTicks = Int64.MaxValue;
DateTime validDate;
// Validate the value.
if (numberOfTicks >= DateTime.MinValue.Ticks &&
numberOfTicks <= DateTime.MaxValue.Ticks)
validDate = new DateTime(numberOfTicks);
else if (numberOfTicks < DateTime.MinValue.Ticks)
System.Console.WriteLine("{0:N0} is less than {1:N0} ticks.",
numberOfTicks,
DateTime.MinValue.Ticks);
else
System.Console.WriteLine("{0:N0} is greater than {1:N0} ticks.",
numberOfTicks,
DateTime.MaxValue.Ticks);
}
}
The code above generates the following result.