Jaa Zaib Jaa Zaib - 2 years ago 89
SQL Question

Get Start and End Time in Sql

I have three Shifts in my office.How i can get name of current running shift using Sql Query ?

Table Description is as given below

Id, Name, startTime, hours

1, Shift1, 6:00 am, 6

2, Shift2, 12:00 pm, 6

3, Shift3, 06:00 pm, 6

Thanks in Advance

Answer Source

For SQL Server I think:

select Id, Name, startTime, hours
from table 
convert(time, getdate()) >= startTime
and convert(time, getdate()) < DATEADD(HH, hours, startTime)

if startTime column type is time.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download