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
 Between Specfic Date and Current Date

Author  Topic 

Johnph
Posting Yak Master

103 Posts

Posted - 2013-05-07 : 12:49:38
Hello,

I have another query

SELECT * FROM TABLE WHERE COLUMN BETWEEN GETDATE()-1 AND GETDATE())


This is my current query, I want to modify it a bit to do:

BETWEEN (YESTERDAY's DATE AT 4:00AM) AND (TODAY's DATE AT 4:00AM)

MuMu88
Aged Yak Warrior

549 Posts

Posted - 2013-05-07 : 13:16:03
Here is a way to do it:

[CODE]

SELECT * FROM TABLE WHERE COLUMN BETWEEN DATEADD(hh, -20, DATEADD(dd, 0, DATEDIFF(dd, 0, getdate()))) AND
DATEADD(hh, 4, DATEADD(dd, 0, DATEDIFF(dd, 0, getdate())));


[/CODE]
Go to Top of Page

Johnph
Posting Yak Master

103 Posts

Posted - 2013-05-07 : 13:47:27
Thank you!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-05-08 : 00:48:37
it will be either of MuMu's suggestion or this


SELECT * FROM TABLE
WHERE COLUMN >= DATEADD(dd,DATEDIFF(dd,0,GETDATE())-1,'04:00')
AND COLUMN < DATEADD(dd,DATEDIFF(dd,0,GETDATE()),'04:00')

depending on whether you want records created at 04:00 AM today to be included or not

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2013-05-17 : 04:37:58
You can find lot of such examples at http://beyondrelational.com/modules/2/blogs/70/posts/10899/understanding-datetime-column-part-iii.aspx

Madhivanan

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

- Advertisement -