I have date and time stored in my database and I don't want to display both, just the date itself. When I store the date/time in a variable how do I output just the date in C#?
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);
DateTime dt = DateTime.Now;
...=dt.ToLongDateString();
...=dt.ToShortDateString();
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