Postgresql query between date ranges

前端 未结 5 1608
轻奢々
轻奢々 2020-12-04 07:51

I am trying to query my postgresql db to return results where a date is in certain month and year. In other words I would like all the values for a month-year.

The

5条回答
  •  渐次进展
    2020-12-04 08:51

    Just in case somebody land here... since 8.1 you can simply use:

    SELECT user_id 
    FROM user_logs 
    WHERE login_date BETWEEN SYMMETRIC '2014-02-01' AND '2014-02-28'
    

    From the docs:

    BETWEEN SYMMETRIC is the same as BETWEEN except there is no requirement that the argument to the left of AND be less than or equal to the argument on the right. If it is not, those two arguments are automatically swapped, so that a nonempty range is always implied.

提交回复
热议问题