本文介绍了计算上一季度的最后一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
计算上一季度最后一天的最有效方法是什么?
What's the most efficient way to calculate the last day of the prior quarter?
示例:给定日期11/19/2008,我想返回9 / 30/2008。
Example: given the date 11/19/2008, I want to return 9/30/2008.
平台是SQL Server
Platform is SQL Server
推荐答案
如果@日期有问题的日期
If @Date has the date in question
Select DateAdd(day, -1, dateadd(qq, DateDiff(qq, 0, @Date), 0))
编辑:感谢下面的@strEagle,更简单的是:
Thanks to @strEagle below, simpler still is:
Select dateadd(qq, DateDiff(qq, 0, @Date), -1)
这篇关于计算上一季度的最后一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!