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
 Getdate Function SQL

Author  Topic 

tugsy
Starting Member

10 Posts

Posted - 2007-04-11 : 17:13:18
I am trying to return data from between 2 dates. in this instance it is returning data from yesterday which works fine.
However I am trying to return data for yesterday before 12 noon.
The following returns yesterdays data.
WHERE
(dbo.People.SystemUser = 1 AND
dbo.Actions.ActionDate > DATEADD(dd, DATEDIFF(dd,0,getdate()), -1) AND
dbo.Actions.ActionDate < DATEADD(dd, DATEDIFF(dd,0,getdate()), 0) AND
dbo.People.PersonId = 'JO')

How would I get it to return only yesterday before midday's data?

Thanks,
Tugsy

sshelper
Posting Yak Master

216 Posts

Posted - 2007-04-11 : 17:18:30
Try this:

WHERE
(dbo.People.SystemUser = 1 AND
dbo.Actions.ActionDate > DATEADD(dd, DATEDIFF(dd,0,getdate()), -1) AND
dbo.Actions.ActionDate < DATEADD(dd, DATEDIFF(dd,0,getdate()), -0.5) AND
dbo.People.PersonId = 'JO')

SQL Server Helper
http://www.sql-server-helper.com
Go to Top of Page

tugsy
Starting Member

10 Posts

Posted - 2007-04-11 : 17:22:42
As simple as that <Blush>! I should have known. Thanks for your help.
Go to Top of Page
   

- Advertisement -