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.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version