views:

374

answers:

7

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.

A: 

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)
Joel Coehoorn
+5  A: 

Use the Date property of the datetime field (if you need to do this on the client)

GvS
A: 

CONVERT(varchar,mydate,101)

Jason Irwin
+2  A: 

DateTime.Date will give you just the date portion of the datetime if you want to pass it around your application

Matthew Steeples
+1  A: 

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()
Mitchel Sellers
+1  A: 

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");
Martin Peck
A: 
CONVERT(DATE, dateFieldName)
Adam Robinson