Calculate the last day of the prior quarter

后端 未结 6 1312
别那么骄傲
别那么骄傲 2020-12-10 16:24

What\'s the most efficient way to calculate the last day of the prior quarter?

Example: given the date 11/19/2008, I want to return 9/30/2008.

Platform is S

6条回答
  •  情深已故
    2020-12-10 17:06

    In amazon redshift:

    Last day of the previous quarter:

    select dateadd(day,-1,DATE_TRUNC('qtr', current_date)) from whatever
    

    Last day of current quarter:

    select dateadd(qtr,1,dateadd(day,-1,DATE_TRUNC('qtr', current_date))) from whatever
    

提交回复
热议问题