Sample Header Ad - 728x90

How to add a day/night indicator to a timestamp column?

2 votes
2 answers
2161 views
There is a timestamp column I use to indicate whether a row was created during day or night time. My code is the following, but for some reason I only get 'DAY' as outcome. Am I not formatting the values right?
select record_id, rec_date,
       case when date_part('hour', rec_date) between 20 and 07 then 'Night'
            else 'Day' end as Indicator
from records;
The rec_date column is a timestamp where I can see values such as 2019-11-20 21:34:02.000000 - which should get a 'Night' indicator.
Asked by ColRow (43 rep)
May 25, 2020, 09:06 PM
Last activity: Jun 7, 2020, 10:22 PM