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
 time between 2 dates

Author  Topic 

arusu
Yak Posting Veteran

60 Posts

Posted - 2010-12-08 : 22:30:02
I have 2 datetimes and I need to check if a third one is in between the time of the first 2

ex

1) 2007-05-07 09:53:01.0376635
2) 2007-05-07 012:53:01.0376635

3) 2007-05-10 011:53:01.0376635

so in this example it should be good because the time in the 3rd date is in between the time in date 1 and date 2

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-12-09 : 00:28:13
First 2007-05-10 is three days greater than 2007-05-07

Can you confirm that date is stored in this format only:
2007-05-10 011:53:01.0376635

I am here to learn from Masters and help new bees in learning.
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-12-09 : 00:31:52
Something to start with:

Select case when left('2007-05-07 14:53:01.0376635',19) between left('2007-05-07 09:53:01.0376635' ,19)
and Cast(left('2007-05-07 012:53:01.0376635' ,19) as datetime) then 'Yes'
Else
'No'
End
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-12-09 : 11:59:52
why do you have padded 0 on left even for hour values 11,12 etc?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -