Jaa Zaib Jaa Zaib - 5 months ago 6
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


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.