Getting results between two dates in PostgreSQL

前端 未结 8 1588
感动是毒
感动是毒 2020-12-07 22:59

I have the following table:

+-----------+-----------+------------+----------+
| id        | user_id   | start_date | end_date |
| (integer) | (integer) | (da         


        
相关标签:
8条回答
  • 2020-12-07 23:26
     SELECT *
       FROM mytable
      WHERE (start_date, end_date) OVERLAPS ('2012-01-01'::DATE, '2012-04-12'::DATE);
    

    Datetime functions is the relevant section in the docs.

    0 讨论(0)
  • 2020-12-07 23:26

    To have a query working in any locale settings, consider formatting the date yourself:

    SELECT * 
      FROM testbed 
     WHERE start_date >= to_date('2012-01-01','YYYY-MM-DD')
       AND end_date <= to_date('2012-04-13','YYYY-MM-DD');
    
    0 讨论(0)
提交回复
热议问题