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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Specify hour with datediff?

Author  Topic 

phoeneous
Starting Member

9 Posts

Posted - 2009-12-03 : 13:32:12
Is it possible to specify an hour when using DATEDIFF? For example
this snippet from my query:

(DATEDIFF(day, acct_banktran.eff_date, { fn NOW() }) <= 1)

I know that this will query all acct_banktran.eff_date that took place
yesterday but it pulls all of them starting from 12:00a.m.. How can I limit
that query to only get specific acct_banktran.eff_date at a certain hour like 4:15p.m.?
Thank you.

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-12-03 : 13:55:28
Put one more condition as like below

(DATEDIFF(day, acct_banktran.eff_date, { fn NOW() }) <= 1) and
'2009-12-04 14:30:00.000' < getdate()

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

phoeneous
Starting Member

9 Posts

Posted - 2009-12-03 : 14:27:58
This is going to be an automated report so there is no manual input of the date. When the report runs, I just need it to always grab yesterdays date at that specific hour.
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-12-03 : 14:35:57
Make use of getdate()-1


and convert(varchar,getdate()-1,101)+' 14:30:00.000' as datetime)< getdate()

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

phoeneous
Starting Member

9 Posts

Posted - 2009-12-03 : 16:10:53
Sorry, Im not much of a sql guy, what would the whole query look like?
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-12-03 : 16:43:44
quote:
Originally posted by phoeneous

Sorry, Im not much of a sql guy, what would the whole query look like?



After you supplied a snippet?

Am I missing something?

How is that possible?




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

phoeneous
Starting Member

9 Posts

Posted - 2009-12-03 : 17:18:38
No. I meant, what would should the code look like with the snippet I have provided and his suggestion.
Go to Top of Page
   

- Advertisement -