Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 12th, 2006, 06:34 PM
Registered User
Join Date: Aug 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default T-SQL Code to get last 6 months

Hi there,

I am trying to get the last 6 months of data from a table in SQL Server 2005. Does any body out there know how to write this code to accomplish this?

Thanks in advance,


Old October 15th, 2006, 08:59 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post

The DATEADD function allows you to compute a date that is 6 months ago:
    DATEADD(m, -6, current_timestamp)
use this to compare your date column:
    SELECT *
      FROM yourtable
     WHERE yourdatecolumn > DATEADD(m, -6, current_timestamp);
Jeff Mason
Custom Apps, Inc.

Similar Threads
Thread Thread Starter Forum Replies Last Post
display all dates within months sanjeev jha Classic ASP Basics 1 June 6th, 2008 12:46 PM
Sql Query to generate months and year arul1984 SQL Server 2000 8 July 23rd, 2007 04:42 PM
Query Help - Display numbers from two Months rkellogg Access 2 September 27th, 2006 08:51 AM
Years to Months Conversion mahajanvit ASP.NET 2.0 Basics 2 September 25th, 2006 11:43 PM
Find months difference tsimsha Classic ASP Databases 4 February 14th, 2005 08:36 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.