Search code examples
postgresqlhourminute

Query between two dates and two times


I'm trying to query a specific range of time, Eg.:

SELECT * FROM production 
WHERE
production.begin BETWEEN '2017/05/15' AND '2017/05/16'  
AND production.begin BETWEEN '00:15' AND '15:00'

The expected result would be productions that began at '2017/05/15 00:15' to '2017/05/15 15:00' and that began at '2017/05/16 00:15' until '2017/05/16 15:00', excluding lines from '2017/05/15 15:01' until '2017/05/16 00:14'.

Thanks!


Solution

  • select * 
    from production 
    where
        production.begin::date between '2017/05/15' and '2017/05/16'  
        and 
        production.begin::time between '00:15' and '15:00'