How to initialize an empty DateTime in C#

CsharpProgrammingServer Side Programming

Set a DateTime to its minimum value.

DateTime.MinValue;

The above will display the minimum value i.e.

1/1/0001

Let us see how to display the minimum value and avoid adding null to a date to initialize it as empty.

Example

 Live Demo

using System;
using System.Linq;
public class Demo {
   public static void Main() {
      DateTime dt = DateTime.MinValue;
      Console.WriteLine(dt);
   }
}

Output

1/1/0001 12:00:00 AM
raja
Published on 12-Sep-2018 12:09:42
Advertisements