user42348
user42348

Reputation: 4319

How to get date part from datetime?

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

Answers (7)

Adam Robinson
Adam Robinson

Reputation: 185643

CONVERT(DATE, dateFieldName)

Upvotes: 0

Martin Peck
Martin Peck

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

Mitchel Sellers
Mitchel Sellers

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

Matthew Steeples
Matthew Steeples

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

Jason Irwin
Jason Irwin

Reputation: 2045

CONVERT(varchar,mydate,101)

Upvotes: 0

GvS
GvS

Reputation: 52518

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

Upvotes: 9

Joel Coehoorn
Joel Coehoorn

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

Related Questions