tags:

views:

337

answers:

3

Besides the DateTime ctor (new DateTime(year, month, day)) , is there any other way to truncate a date?

+6  A: 

DateTime.Date

Returns just the date component (the time is midnight).

Jon B
+2  A: 
DateTime.Now.ToShortDateString();

Also, ToString() is overloaded in DateTime, you can pass a few dozen formatting options to it.

See: http://authors.aspalliance.com/aspxtreme/sys/demos/datetimeformats.aspx

FlySwat
I'm disappointed in you Jon. I've come to expect better from you! Hey - check out my answer to the Asynchronous Linq question. Pretty sweet.
TheSoftwareJedi
Meh, I just misunderstood what he was asking for. I thought he wanted to know how to format its output to not contain time info, not that he wanted a date object with no time.
FlySwat
Jon - saw your comment on the other answer. You're forgiven. I hate when people do that.
TheSoftwareJedi
Its all good Dana.
FlySwat
A: 

Jonathan, excellent information, thank you

nmiranda