Solved

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

Posted on 2009-05-15
2
756 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

911 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

21 Experts available now in Live!

Get 1:1 Help Now