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

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

WBOY
Release: 2016-06-07 17:47:43
Original
3051 people have browsed it

查询给定日期是当月的第几周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

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template