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)
 Time Range

Author  Topic 

dewacorp.alliances

452 Posts

Posted - 2008-04-21 : 16:29:39
Hi there

I am using SQL2005 and would like to check the whether the time is within the valid range for instance:

Data to check: 2:15AM

Range is between: 01:00AM till 06:59AM, 07:00AM till 02:00 PM

I can use the datepart for hh but that is not what I want. I want to have a full time: HH:MM cause sometimes if you do datepart by hour and if you apply into the above excample will be:

2 BETWEEN 1 AND 6 (this is ok)
2 BETWEEN 7 AND 2 (this is not ok)

Any idea?




jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2008-04-21 : 16:44:47
datepart(hour, @date) returns an int between 0 and 23. so your second check should be this:

datepart(hour, mydatecolumn) between 7 and 14


elsasoft.org
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2008-04-21 : 17:47:19
actually probably needs to be between 7 and 13.


elsasoft.org
Go to Top of Page

dewacorp.alliances

452 Posts

Posted - 2008-04-21 : 19:22:34
Hi there

I think you are right it actually returns 0-23. My mistake.

Thanks

quote:
Originally posted by jezemine

actually probably needs to be between 7 and 13.


elsasoft.org

Go to Top of Page
   

- Advertisement -