SQL query show items from the last twelve month

I have  a table with a date field and i want to write a query where i only show the last twelve months. How?
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.

Jim HornMicrosoft SQL Server Data DudeCommented:
You'll want to provide a more exact definition of 'last twelve months, but in general
(air code, modify to meet your needs)
FROM your_table
WHERE some_date_field >= DATEADD(month, 12, GETDATE()) AND some_date_field < GETDATE()

Open in new window

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
Daniel Van Der WerkenIndependent ConsultantCommented:
You could try this too:

FROM your_table

Open in new window

Which would return anything created between a year before now and now, more or less. I like using the BETWEEN keyword.
PortletPaulEE Topic AdvisorCommented:
I strongly caution against using BETWEEN for date ranges. Please see: "Beware of Between"

the best practice with date and time ranges is to avoid BETWEEN and to always use the form:

WHERE col >= '20120101' AND col < '20120201'
This form works with all types and all precisions, regardless of whether the time part is applicable.
Itzik Ben-Gan

I would follow the pattern suggested by Jim.

Just one small but important point though is that you state the column is of Dates, if it is of higher precision (e.g. smalldatetime, datetime or datetime2) THEN you need to take account of time too

to set time to 00:00:00 from getdate() you can use
      cast(getdate() as date)
     dateadd(day, datediff(day,0, getdate() ), 0)

FROM your_table
WHERE some_date_field >= DATEADD(month, 12, dateadd(day, datediff(day,0, getdate() ), 0) )
AND some_date_field < GETDATE()
vbnetcoderAuthor Commented:
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

From novice to tech pro — start learning today.