Remove time from a date/time string
DateTime dt = DateTime.Now;
...=dt.ToLongDateString();
...=dt.ToShortDateString();
It kind of depends where you are writing it to. The format specifier is either "{0:d}" or "{0:D}". But it depends if you are using ToString(), ToShortDateString(), ToLongDateString(), some sort of grid control, or something else altogether.
If you just want the date portion of a System.DateTime
structure, you can use the Date
property (System.DateTime.Date). It strips out hours, minutes, seconds and milliseconds.
So, if your database column datatype is defined as datetime or similar (which is the general recommandation if your database supports it), you don't have to use string and string formats.
This is very useful:
http://www.csharp-examples.net/string-format-datetime/
In your case I would say:
DateTime dt = new DateTime(2008, 3, 9, 16, 5, 7, 123);
String.Format("{0:MM/dd/yy}", dt);