当前位置:数据库 > SQLServer >>

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

查询季度初末,年上下个季度初末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
补充:数据库,Mssql
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,