Reputation: 4319
I have a datetime for eg:23/9/2009 10:00:00 AM .I want to get date from datetime.Means 23/9/2009 .Can anybody help
Upvotes: 3
Views: 15915
Reputation: 61
Another way besides the ToShortDateString Function. Here we use a format string to get our result.
dim myDateFormat as String = "MM/d/yyyy"
dim myDateTime as DateTime = DateTime.Now 'Displays: 1/17/2014 2:33:23 PM
dim myDateOnly as DateTime = myDateTime.ToString(format) 'Displays: 1/17/2004
Upvotes: 0
Reputation: 3928
Just do
DateTime dateOnly = myDateTime.Date;
To display it as a date you can do
string dateString = dateOnly.ToShortDateString();
Note, that ToShortDateString will work even with a time component.
Upvotes: 10
Reputation:
you can do it this way:
DateTime.Parse("23/9/2009 10:00:00").Date.ToString()
Upvotes: 2
Reputation: 2918
Searching the web always helps.
Google 'datetime msdn' and you'll get the best reference material.
Upvotes: 1