Quantcast
Channel: How to remove time portion of date in C# in DateTime object only? - Stack Overflow
Viewing all articles
Browse latest Browse all 42

Answer by Guillermo Gutiérrez for How to remove time portion of date in C# in DateTime object only?

$
0
0

I know this is an old post with many answers, but I haven't seen this way of removing the time portion. Suppose you have a DateTime variable called myDate, with the date with time part. You can create a new DateTime object from it, without the time part, using this constructor:

public DateTime(int year, int month, int day);

Like this:

myDate = new DateTime(myDate.Year, myDate.Month, myDate.Day);

This way you create a new DateTime object based on the old one, with 00:00:00 as time part.


Viewing all articles
Browse latest Browse all 42

Trending Articles