How to get week start and end date string in PostgreSQL?

前端 未结 4 1396
野性不改
野性不改 2020-12-25 10:47

I am using PostgreSQL 8.3. I have a table like this:

id        regist_time        result
-----------------------------------
1     2012-07-0         


        
4条回答
  •  暖寄归人
    2020-12-25 11:31

    This can help, a query to get all days of current week.

    select cast(date_trunc('week', current_date) as date) + i
    from generate_series(0,6) i
    

    2015-08-17
    2015-08-18
    2015-08-19
    2015-08-20
    2015-08-21

    To get week start and end date (as 0 for Monday and 4 for Friday):

    select cast(date_trunc('week', current_date) as date) + 0 || '-->' ||  cast(date_trunc('week', current_date) as date) + 4;
    

    2015-08-17-->2015-08-21

提交回复
热议问题