Reputation: 869
I have a datetime variable in my application. Its value is 01/09/2010 00:00:00. I want to get value of 01/09/2010. Still I want to use the DateTime structure. Is there any method/property for that. I know it is possible using conversion. For example I have DateTime date = new DateTime(2010,09,01); It will display 01/09/2010 00:00:00
I want date to be 01/09/2010 alone.
Is it possible?
Upvotes: 1
Views: 1534
Reputation: 3967
Are you looking for a way to format the date for display/printing purposes, or to get rid of the time part if it is given?
Use the DateTime.ToShortDateString()
method or the DateTime.Date
property, respectively.
Upvotes: 1
Reputation: 60694
Call date.ToShortDateString()
so see only the date part of the DateTime
object.
To force a specific format (if that is not your default culture format), you can use
date.ToString("dd/MM/yyyy");
Note that Im not sure if 01
or 09
is the month in your example. If I have mixed them up, just replace "dd/MM/yyyy"
with "MM/dd/yyyy"
Upvotes: 5