Reputation: 4319
Duplicate: How to truncate a date in .net?
I have datetime field containing '4/1/2009 8:00:00AM'. I want to get '4/1/2009' without the time.
Upvotes: 2
Views: 11686
Reputation: 11544
This is C# (yeah - I know you want VB) but given that none of the following uses anything other than DataTime then it should give you want you want...
string foo = "4/1/2009 8:00:00AM";
DateTime bar = DateTime.Parse(foo);
string output = bar.ToString("M/d/yyyy");
Upvotes: 1
Reputation: 63126
If you are inside of .NET as it appears that you are based on the tags
dim myDate as DateTime = DateTime.Parse('4/1/2009 8:00:00AM')
dim myDesiredValue as String = myDate.ToShortDateString()
Upvotes: 3
Reputation: 8058
DateTime.Date will give you just the date portion of the datetime if you want to pass it around your application
Upvotes: 3
Reputation: 52518
Use the Date property of the datetime field (if you need to do this on the client)
Upvotes: 9
Reputation: 415745
Depends on your database server, but in sql server I normally use this in my sql query:
CAST(FLOOR(CAST([MyDateTimeColumn] AS float)) AS datetime)
Upvotes: 0