Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Subtract 30 Days

Author  Topic 

accessdbguru
Starting Member

26 Posts

Posted - 2012-02-01 : 14:47:31
I need to write a query to pull 30 days from current date.
Field name [Timestamp] format is DateTime. How i do this?


SELECT TimeStamp, ApplicationName, PercentageValue
FROM dbo.SMS_Application_Status
WHERE (TimeStamp = GETDATE() - (DATEDIFF, 'day', GETDATE()-30);

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-01 : 15:03:07
[code]
...
WHERE TimeStamp >= DATEADD(day,DATEDIFF( day, 0,GETDATE())-30,0)
AND TimeStamp < DATEADD(day,DATEDIFF( day, 0,GETDATE())+1,0)
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-01 : 15:05:46
see similar logics you can use for date values here

http://visakhm.blogspot.com/2010/01/some-quick-tips-for-date-formating.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -