I'm trying to store a shortened date (mm/dd/yyyy) into a DateTime object. The following code below is what I am currently trying to do; this includes the time (12:00:00 AM) which I do not want :(
DateTime goodDateHolder = Convert.ToDateTime(DateTime.Now.ToShortDateString());
Result will be 10/19/2009 12:00:00 AM
1. In most countries of the world, dates are written in order DAY/MONTH/YEAR, e.g., 4 July 1999, abbreviated 4/7/1999. 2. In eastern Asia, however, dates are written in order YEAR/MONTH/DAY: 1999 July 4, abbreviated 1999/7/4.
ToString() − One more way to get the date from DateTime is using ToString() extension method. The advantage of using ToString() extension method is that we can specify the format of the date that we want to fetch. DateTime. Date − will also remove the time from the DateTime and provides us the Date only.
The string returned by the ToShortDateString method is culture-sensitive. It reflects the pattern defined by the current culture's DateTimeFormatInfo. ShortDatePattern property. For example, for the en-US culture, the standard short date pattern is "M/d/yyyy"; for the de-DE culture, it is "dd.
You only have two options in this situation.
1) Ignore the time part of the value.
2) Create a wrapper class.
Personally, I am inclined to use option 1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With