Saaharjit Singh
Saaharjit Singh

Reputation: 125

Show data depending on the time of the day

I have a table that shows the amount of units produced by an employee. It also has the transaction time.

Is it possible to display data in such a way that when the current time is between 7 am to 3 pm it should only display the transaction that took place during that period of time and then when the current time is 3pm then it should only display the transactions between 3-11 pm.

sample data

units | name | TIME
-------------------------
 10 | aa       | 08:33:22
 26 | bb       | 10:33:22
 36 | cc       | 16:33:22
 11 | dd       | 18:33:22

Now if the current time is 13:00:00 i want all the transcations between 7am to 3pm which will be just the first 2. But when the time is 15:00:00 then it should automatically show all the transactions between 3pm - 11pm

Upvotes: 0

Views: 46

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269513

You can use where:

where (datepart(hour, getdate()) between 7 and 14 and
       datepart(hour, transactiondatetime) between 7 and 14
      ) or
      (datepart(hour, getdate()) not between 7 and 14 and
       datepart(hour, transactiondatetime) between 11 and 22
      )

Upvotes: 1

Related Questions