Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove time from a date/time string

Tags:

c#

.net

datetime

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#?

like image 707
The Muffin Man Avatar asked Dec 05 '10 06:12

The Muffin Man


2 Answers

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);  
like image 161
Ives.me Avatar answered Oct 05 '22 22:10

Ives.me


DateTime dt = DateTime.Now;
...=dt.ToLongDateString();
...=dt.ToShortDateString();
like image 24
royas Avatar answered Oct 06 '22 00:10

royas