Quantcast
Viewing latest article 21
Browse Latest Browse All 42

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

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 latest article 21
Browse Latest Browse All 42

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>