sql select statement today’s date - 20 days?

February 15, 2010 - 4:12 am

Hi,

I want to use the SELECT statement to get all my records from my table which is 20 days from the current date. I have been trying all ways but can’t get it.. help will be appreciated!

SELECT WEIGHT, TIME, USER_ID
FROM dbo.WeightTable
WHERE (USR_ID = ‘abc’) AND ….(what to put here)

i am using ms sql server management studio express.. 2005 version. thanks!

SELECT WEIGHT, TIME, USER_ID
FROM dbo.WeightTable
WHERE (USR_ID = ‘abc’)
AND time > dateadd(day, -20, getDate())

3 Responses to “sql select statement today’s date - 20 days?”

  1. Jenna Says:

    Alright so you want all the tables from 20 days till now?

    You want to get the date of 20 days ago then use a > that date to get all them.

    There is a thing on google somewhere to get the dates\times and make them to numbers but I forget where
    References :

  2. doug a Says:

    SELECT WEIGHT, TIME, USER_ID
    FROM dbo.WeightTable
    WHERE (USR_ID = ‘abc’) and time>getdate()-20

    this is assuming time is formatted as a standard SQL dateformat

    getdate function reurns the current date

    ie select getdate()-20 will show you the date 20 days ago.

    hope this helps
    References :

  3. Hal 9000 Says:

    SELECT WEIGHT, TIME, USER_ID
    FROM dbo.WeightTable
    WHERE (USR_ID = ‘abc’)
    AND time > dateadd(day, -20, getDate())
    References :

Leave a Reply