Getting the date without the time

I have a datefield that basically represents its date in this format.

2009-12-15 16:20:44.930

I need to extract the date part ie '2009-12' for a group by and order by section of a query.

Can someone show me how this could be done.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris LuttrellSenior Database ArchitectCommented:
if you are wanting Date (2009-12-15) then cast or convert to just DATE datatype in 2008.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Aneesh RetnakaranDatabase AdministratorCommented:
convert (varchar(7), datefield, 120 )
select convert (varchar(10), datefield, 101)
You can use a convertion to obtain the information

SELECT CONVERT(nvarchar(7), myDate, 126) FROM Table
Group By CONVERT(nvarchar(7), GETDATE(), 126)
Chris LuttrellSenior Database ArchitectCommented:
select your_columns
from your_table
group by convert(DATE, datefield)
order by convert(DATE, datefield)

-- to properly order and group by just Year and Month do it this way
select your_columns
from your_table
group by Year(datefield), Month(datefield)
order by Year(datefield), Month(datefield)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.