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

Posted on 2009-05-15
Last Modified: 2013-12-07

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.

Question by:Saroj13
LVL 21

Expert Comment

ID: 24399235
Try this:

FROM Table1
WHERE LiveData > GETDATE() - 30


LVL 13

Accepted Solution

St3veMax earned 500 total points
ID: 24399340

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)


Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
convert in derived column 7 30
SQL Query including math and 2 tables problem 26 51
Oracle dataguard 5 32
Need some help to cast ntext to nvarchar SQL 2000 7 34
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
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 explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

777 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