Solved

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

Posted on 2009-05-15
2
754 Views
Last Modified: 2013-12-07
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
Comment
Question by:Saroj13
2 Comments
 
LVL 21

Expert Comment

by:JestersGrind
ID: 24399235
Try this:

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

Greg


0
 
LVL 13

Accepted Solution

by:
St3veMax earned 500 total points
ID: 24399340
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now