Calculate the last day of the prior quarter

后端 未结 6 1314
别那么骄傲
别那么骄傲 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-10 17:09

    I came up with this (tested for all months):

    select dateadd(dd,-1,dateadd(qq,datediff(qq,0,'11/19/2008'),0)),
           dateadd(dd,-1,dateadd(qq,datediff(qq,0,'10/19/2008'),0)),
           dateadd(dd,-1,dateadd(qq,datediff(qq,0,'12/19/2008'),0))
    

    It might turn out to be the simplest.

提交回复
热议问题