查询季度初末,年上下个季度初末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