Nelson Miranda
Nelson Miranda

Reputation: 5554

How to truncate a date in .net?

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

Upvotes: 4

Views: 6840

Answers (2)

FlySwat
FlySwat

Reputation: 175653

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

Upvotes: 3

user27414
user27414

Reputation:

DateTime.Date

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

Upvotes: 15

Related Questions