Home > Database > Mysql Tutorial > sql 计算给定日期所在月与所在季度的天数的sql语句

sql 计算给定日期所在月与所在季度的天数的sql语句

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 17:47:38
Original
1663 people have browsed it

sql 计算给定日期所在月与所在季度的天数的sql语句

sql 计算给定日期所在月与所在季度的天数的sql语句

declare @date datetime;
set @date = getdate()
--本月度第一天与下月度第一天所差的天数
select datediff(day,dateadd(month,datediff(month,0,@date),0),dateadd(month,1+datediff(month,0,@date),0))
--借助变量简化
select @date = dateadd(month,datediff(month,0,@date),0) --本月度第一天
select datediff(day,@date,dateadd(month,1,@date))
--另一种思路:给定月最后一天的日期,记为本月天数
select day(dateadd(month,datediff(month,-1,@date),-1))
go

--计算给定日期所在季度的天数

declare @date datetime;
set @date = getdate()
--本季度第一天与下季度第一天所差的天数
select datediff(day,dateadd(quarter,datediff(quarter,0,@date),0),dateadd(quarter,1+datediff(quarter,0,@date),0))
--借助变量简化
select @date = dateadd(quarter,datediff(quarter,0,@date),0) --本季度第一天
select datediff(day,@date,dateadd(quarter,1,@date))
go
Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
sql file
From 1970-01-01 08:00:00
0
0
0
php - Overhead of prepare vs sql?
From 1970-01-01 08:00:00
0
0
0
Print sql statement
From 1970-01-01 08:00:00
0
0
0
Pass array to SQL insert query using PHP
From 1970-01-01 08:00:00
0
0
0
sql optimization or
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template