Getting date list in a range in PostgreSQL

后端 未结 8 435
悲&欢浪女
悲&欢浪女 2020-11-28 07:59

I\'d like to get the list of days between the two dates (including them) in a PostgreSQL database. For example, if I had:

  • start date: 29 june
相关标签:
8条回答
  • 2020-11-28 08:39
    select generate_series('2012-06-29', '2012-07-03', '1 day'::interval)::date;
    
    0 讨论(0)
  • 2020-11-28 08:39

    If you already have database that you want to query:

    SELECT
       TO_CHAR(date_column,'DD Mon YYYY')
    FROM
       some_table
    WHERE
       date_column BETWEEN '29 Jun 2012' AND '3 JUL 2012'
    
    GROUP BY date_column
    ORDER BY date_column
    

    This will result in:

    "29 Jun 2012"
    "30 Jun 2012"
    "01 Jul 2012"
    "02 Jul 2012"
    "03 Jul 2012"
    
    0 讨论(0)
提交回复
热议问题