C# DateTime MinValue
Description
DateTime MinValue
represents the smallest possible
value of DateTime. This field is read-only.
Syntax
DateTime.MinValue
has the following syntax.
public static readonly DateTime MinValue
Example
Represents the smallest possible value of DateTime.
using System;/* w ww. ja v a 2 s.c om*/
public class MainClass{
public static void Main(String[] argv){
DateTime date1 = new DateTime();
Console.Write(date1);
if (date1.Equals(DateTime.MinValue)){
System.Console.WriteLine(" (Equals Date.MinValue)");
}
}
}
The code above generates the following result.
Example 2
The following code shows how to uses the DateTime.MinValue and get the ticks value.
using System;//from w ww .j ava 2 s. c o m
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.