Home >Database >Mysql Tutorial >查询给定日期是当月的第几周sql查询语句

查询给定日期是当月的第几周sql查询语句

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

查询给定日期是当月的第几周sql查询语句
declare @date datetime;
set @date = getdate()
--思路,给定日期是当年的第几周-给定日期所在月第一天是当年的第几周
select datepart(week,@date)-datepart(week,dateadd(month,datediff(month,0,@date),0))+1 [weekofmonth]
select datepart(week,@date)-datepart(week,dateadd(day,1-datepart(day,@date),@date))+1 [weekofmonth]
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