T-SQL, Select a date range from now and 6 months in past.

Hi Guys.

I need to find a way in t-sql to select a date range from now to 6 months in the past.

We have a field name called DatePublished that holds the date the item was added to the database.

So the results that would come back would be 6 months worth of stories.

Who is Participating?
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
check out DATEADD() function:

in short:
where datepublished >= dateadd(month, -6, getdate())
  and datepublished < getdate()

Open in new window

Guy Hengel [angelIII / a3]Billing EngineerCommented:
note: getdate() is now, date + time.
if you need full day, resp full month, you will need to add some more to get the "corrected" date value...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.