How to compare dates in datetime fields in Postgresql?

后端 未结 4 798
太阳男子
太阳男子 2020-12-07 10:05

I have been facing a strange scenario when comparing dates in postgresql(version 9.2.4 in windows).
I have a column in my table say update_date with type \'timestamp w

4条回答
  •  甜味超标
    2020-12-07 10:36

    Use the range type. If the user enter a date:

    select *
    from table
    where
        update_date
        <@
        tsrange('2013-05-03', '2013-05-03'::date + 1, '[)');
    

    If the user enters timestamps then you don't need the ::date + 1 part

    http://www.postgresql.org/docs/9.2/static/rangetypes.html

    http://www.postgresql.org/docs/9.2/static/functions-range.html

提交回复
热议问题