Home >Database >Mysql Tutorial >查询季度初末,年上下个季度初末sql语句

查询季度初末,年上下个季度初末sql语句

WBOY
WBOYOriginal
2016-06-07 17:47:373535browse

查询季度初末,年上下个季度初末sql语句

declare @date  datetime
set @date=getdate()
--季度初,计算给定日期所在季度的第一天
select dateadd(quarter,datediff(quarter,0,@date),0) as '当前季度的第一天'
--季度末,计算给定日期所在季度的最后一天
select dateadd(quarter,1+datediff(quarter,0,@date),-1) as '当前季度的最后一天'
--上个季度初
select dateadd(quarter,datediff(quarter,0,@date)-1,0) as '当前季度的上个季度初'
--上个季度末
select dateadd(quarter,datediff(quarter,0,@date),-1) as '当前季度的上个季度末'
--下个季度初
select dateadd(quarter,1+datediff(quarter,0,@date),0) as '当前季度的下个季度初'
--下个季度末
select dateadd(quarter,2+datediff(quarter,0,@date),-1) as '当前季度的下个季度末'
go
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn