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)
 Easy Time select???

Author  Topic 

ddobbertin
Yak Posting Veteran

51 Posts

Posted - 2008-08-27 : 08:12:46
Very tired....my brain is just not in it today. This is easy and quick if someone could help.

I have a timestamp field on a customer's database in the format of '08/27/2008 05:55:24.454'.

I need to be able to query that timestamp field to assign workers shifts.

Example:

Update punchedin set shift = '1' where timestamp between '05:00:00.000' and '13:00:00.000'

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-08-27 : 08:19:04
[code]
Update punchedin
set shift = '1'
where datepart(hour, timestamp) between 5 and 13[/code]



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

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-27 : 08:29:50
Is '13:00:00.000' inclusive?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

ddobbertin
Yak Posting Veteran

51 Posts

Posted - 2008-08-27 : 08:56:50
'13:00:00.000' is inclusive. Those were also just examples. The times would be more like '03:45:00.000' and '16:25:00.000'. I was thinking the same thing with doing datepart for the hour and minutes but thought maybe there was a cleaner more efficient way to get it done.
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-08-27 : 09:03:49
The functions and examples here should help you:

http://weblogs.sqlteam.com/jeffs/archive/2007/01/02/56079.aspx

you can say:

where dbo.TimeOnly(yourDate) between dbo.Time(3,45,0) and dbo.Time(16,25,0)


- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page
   

- Advertisement -