SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Between Specfic Date and Current Date
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Johnph
Yak Posting Veteran

95 Posts

Posted - 05/07/2013 :  12:49:38  Show Profile  Reply with Quote
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

547 Posts

Posted - 05/07/2013 :  13:16:03  Show Profile  Reply with Quote
Here is a way to do it:



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())));


Go to Top of Page

Johnph
Yak Posting Veteran

95 Posts

Posted - 05/07/2013 :  13:47:27  Show Profile  Reply with Quote
Thank you!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 05/08/2013 :  00:48:37  Show Profile  Reply with Quote
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

India
22755 Posts

Posted - 05/17/2013 :  04:37:58  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.11 seconds. Powered By: Snitz Forums 2000