Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 795
  • Last Modified:

Sql query to get data from last 30 days from today's date and time?

Hi,

I am using Sql Server 2005. I have a column Livedate. I want data which is added in the last 30 days from today's date and time.

Thanks
0
Saroj13
Asked:
Saroj13
1 Solution
 
JestersGrindCommented:
Try this:

SELECT *
FROM Table1
WHERE LiveData > GETDATE() - 30

Greg


0
 
St3veMaxCommented:
Or...

WHERE LiveData > dateadd(day, -30, datediff(d,0,GetDate()))

This will give you all results from the start of the day (i.e. 15/04/2009 00:00:00); Not results from -30 days ago at 15/04/2009 21:18 (the time I ran this)

HTH
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Tackle projects and never again get stuck behind a technical roadblock.
Join Now