views:

2859

answers:

4

How do you format the date time to just date?

for example, this is what i retrievedd from the database: 12/31/2008 12:00:00 AM, but i just want to show the date and no time.

+13  A: 

Either use one of the standard date and time format strings which only specifies the date (e.g. "D" or "d"), or a custom date and time format string which only uses the date parts (e.g. "yyyy/MM/dd").

Jon Skeet
for example: DateTime.Now.ToString("d")
schmoopy
+1  A: 

FormatDateTime(Now, DateFormat.ShortDate)

madcolor
A: 

Or, if for some reason you don't like any of the more sensible answers, just discard everything to the right of (and including) the space.

Brian Knoblauch
+6  A: 

I almost always use the standard formating ShortDateString, because I want the user to be in control of the actual output of the date.

Code

   Dim d As DateTime = Now
   Debug.WriteLine(d.ToLongDateString)
   Debug.WriteLine(d.ToShortDateString)
   Debug.WriteLine(d.ToString("d"))
   Debug.WriteLine(d.ToString("yyyy-MM-dd"))

Results

Wednesday, December 10, 2008
12/10/2008
12/10/2008
2008-12-10

Note that these results will vary depending on the culture settings on your computer.

Rick