Reputation: 23
I have datetime like:
01-Jan-10 12:00:00 AM
I want to get only 01-Jan-10
.I do not know how to convert it. Anyone know help me please, Thanks,
Upvotes: 0
Views: 1045
Reputation: 13460
use method DateTime.ToShortDateString();
or DateTime.ToLongDateString()
Upvotes: 0
Reputation: 8818
Like this:
DateTime dt = DateTime.Today; //or whatever
string dateString = dt.ToShortDateString();
You can also use ToString()
to format it however you like. In your case, it would be:
string dateString = dt.ToString("dd-MMM-YY");
Upvotes: 0
Reputation: 74949
If you have a DateTime
object and want to get the string in that format, use myDateTime.ToString("dd-MMM-yy")
. If you have a DateTime
object and want to return a new DateTime
object that is just the date component, use DateTime.Date
.
Upvotes: 4