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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Stored Proc - Rewrite 42 70
pl/sql parameter is null sometimes 2 23
Subquery in the where statement always shows up null in the result 5 40
SQL Pivot table 2 42
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 post first appeared at Oracleinaction  ( 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…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

685 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