Thursday, December 8, 2011

Sql select statement today's date - 20 days?

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 %26gt; dateadd(day, -20, getDate())|||SELECT WEIGHT, TIME, USER_ID


FROM dbo.WeightTable


WHERE (USR_ID = 'abc') and time%26gt;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|||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 %26gt; 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

No comments:

Post a Comment