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
 capture data for yestarday's date

Author  Topic 

dutyfree
Starting Member

5 Posts

Posted - 2007-09-03 : 05:14:43
I have a table with a field "StartedAt". I wish to capture all the data in that table which has Yestarday's StartAt date.
My script below captures the data which has yestardays "StartedAt" info as well as today's date till now. How can i capture only yestardays info only.

SELECT StartedAt
FROM myTable
WHERE StartedAt >= DATEADD(day, DATEDIFF(day, 0, getdate()), -1)

please help.

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-09-03 : 05:16:57
add an upper boundry:
WHERE StartedAt >= DATEADD(day, DATEDIFF(day, 0, getdate()), -1) and StartedAt < DATEADD(day, DATEDIFF(day, 0, getdate()), 0)

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

mwjdavidson
Aged Yak Warrior

735 Posts

Posted - 2007-09-03 : 05:18:09
[code]SELECT StartedAt
FROM myTable
WHERE StartedAt >= DATEADD(day, DATEDIFF(day, 0, getdate()), -1)
AND StartedAt < DATEADD(day, DATEDIFF(day, 0, getdate()), 0)
[/code]

Mark
Go to Top of Page

mwjdavidson
Aged Yak Warrior

735 Posts

Posted - 2007-09-03 : 05:22:45


Mark
Go to Top of Page

dutyfree
Starting Member

5 Posts

Posted - 2007-09-03 : 05:23:57
Thanks very much guys. Made my life easier.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-09-03 : 05:50:01
www.sql-server-perfromance.com/fk_datetime.asp

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -