There is a table from which you need to select applications received from 20.00 to 08.00, you need to do this for a month for example. How to describe the date in this case?

Request:

Select Номер заявки From Таблица Where Условия and Условия and время поступления заявки = 01.01.2016 - 02.01.2016 hh24:mi:ss - 20.00.00 - 08:00:00 

Update

Here are the date entries now:

 to_char(datestamp,'dd.mm.yyyy hh24:mi:ss') and CAST(TO_DATE('1970-01-01', 'YYYY-MM-DD')+((act1.a3)/86400+4/24)AS TIMESTAMP) >= to_date('01.03.2015','dd.mm.yyyy') and CAST(TO_DATE('1970-01-01', 'YYYY-MM-DD')+((act1.a3)/86400+4/24)AS TIMESTAMP) <= to_date('01.04.2015','dd.mm.yyyy') 
  • Time and date stored in different fields? - MichaelPak

1 answer 1

In the postgresql dialect

 SELECT date_part('hour', calltime) as CallHour FROM table WHERE date_part('hour', calltime)<8 OR date_part('hour', calltime)>20 

For other dialects, datepart may be called.

And quite a clinical case - to convert to the string format "HH" (take only hours) and work with it.

  • Thanks @betonimig for checking and editing - Sergey Mitrofanov
  • Or you can paint for a teapot) - Anton