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 in where clause with datetime datatype

Author  Topic 

crugerenator
Posting Yak Master

126 Posts

Posted - 2010-06-23 : 19:36:14
I've got a where clause where I'm trying to do a between time of exactly one day (which is the value I am being passed as dd/mm/yyyy) and +1 day at 3:00pm after that day.

So, if I was passed a date of 10/10/2010, I need to do:

'between 10/10/2010 00:00:00 and 10/11/2010 13:00:00'

Any help is appreciated... thanks.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-06-23 : 22:12:32
between '20101010' and '20101011 15:00'


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2010-06-24 : 02:37:34
DECLARE @fromdate datetime = '20101010'
SELECT * FROM myTable WHERE DateTimeColumn BETWEEN @fromdate AND DATEADD(hour, 39, @fromdate)

- Lumbago

My blog (yes, I have a blog now! just not that much content yet)
-> www.thefirstsql.com
Go to Top of Page

crugerenator
Posting Yak Master

126 Posts

Posted - 2010-06-24 : 13:39:15
quote:
Originally posted by Lumbago

DECLARE @fromdate datetime = '20101010'
SELECT * FROM myTable WHERE DateTimeColumn BETWEEN @fromdate AND DATEADD(hour, 39, @fromdate)

- Lumbago

My blog (yes, I have a blog now! just not that much content yet)
-> www.thefirstsql.com





Perfect, thanks!
Go to Top of Page
   

- Advertisement -