user42348
user42348

Reputation: 4319

How to get date from datetime format

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

Answers (5)

Jose G
Jose G

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

Gromer
Gromer

Reputation: 9931

Yeah, the .Date property will give you what you need.

Upvotes: 2

Steven
Steven

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

user434917
user434917

Reputation:

you can do it this way:

DateTime.Parse("23/9/2009 10:00:00").Date.ToString()

Upvotes: 2

Gabriel Florit
Gabriel Florit

Reputation: 2918

Searching the web always helps.

Google 'datetime msdn' and you'll get the best reference material.

Upvotes: 1

Related Questions