how to get only Day/month/year from DateTime from datetime.Now in C# code example

Example 1: c# datetime

var dat1 = new DateTime();
// The following method call displays 1/1/0001 12:00:00 AM.
Console.WriteLine(dat1.ToString(System.Globalization.CultureInfo.InvariantCulture));
// The following method call displays True.
Console.WriteLine(dat1.Equals(DateTime.MinValue));

Example 2: c# remove time in datetime

var dateAndTime = DateTime.Now;
var date = dateAndTime.Date;

Example 3: get day month year from date c#

// can add : or / to seperate dates and time
DateTime.Now.ToString("yyyyMMddhhmmss")

Tags:

Java Example