怎么抓某年月第二个周一是几号,在线结贴..

gopark 2007-06-20 10:49:15
怎么抓某年月第二个周一是几号,在线结贴..
...全文
300 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
lwl0606 2007-06-20
  • 打赏
  • 举报
回复
DECLARE @y nvarchar(5)
declare @m nvarchar(2)
set @y='2007'
set @m='1'
declare @a datetime
set @a=@y+'-'+@m+'-1'
select dateadd(d,(8-(datepart(dw,@a)-1))%7+7,@a)

--2007-01-08 00:00:00.000
lwl0606 2007-06-20
  • 打赏
  • 举报
回复
DECLARE @y nvarchar(5)
declare @m nvarchar(2)
set @y='2007'
set @m='12'
declare @a datetime
set @a=@y+'-'+@m+'-1'
select dateadd(d,(8-(datepart(dw,@a)-1))%7+7,@a)



--2007-12-10 00:00:00.000
sp4 2007-06-20
  • 打赏
  • 举报
回复
set datefirst 1
declare @d varchar(20)
set @d='200706'

set @d=@d+'01'
select dateadd(day,15-DATEPART(weekday,@d),@d)
Zack999 2007-06-20
  • 打赏
  • 举报
回复
declare @s varchar(20)
declare @t datetime
set @s='2007-2'
set @t=convert(datetime,@s+'-1')
select DATEADD(wk, DATEDIFF(wk,0, dateadd(dd,6-datepart(day,@t),@t) ), 7)
--结果:2007-2-12
肥胖的柠檬 2007-06-20
  • 打赏
  • 举报
回复
declare @s varchar(20)
set @s='2007-7'
set @s=@s+'-1'
select dateadd(dd,9-DATEPART(dw,@s),@s)
Zack999 2007-06-20
  • 打赏
  • 举报
回复
declare @s varchar(20)
declare @t datetime
set @s='2007-6'
set @t=convert(datetime,@s+'-1')
select DATEADD(wk, DATEDIFF(wk,0, dateadd(dd,6-datepart(day,@t),@t) ), 7)

--结果:2007-6-11
昵称被占用了 2007-06-20
  • 打赏
  • 举报
回复
上面结果
2007-6-11

declare @s varchar(20)
set @s='2007-7' --年月

select top 1 @s+'-'+cast(d as varchar)
from (
select 1 as d
union all
select 2
union all
select 3
union all
select 4
union all
select 5
union all
select 6
union all
select 7
union all
select 8
union all
select 9
union all
select 10
union all
select 11
union all
select 12
union all
select 13
) as t
where datepart(weekday,@s+'-'+cast(d as varchar))=2
order by d desc

--结果
2007-7-9
昵称被占用了 2007-06-20
  • 打赏
  • 举报
回复
declare @s varchar(20)
set @s='2007-6' --年月

select top 1 @s+'-'+cast(d as varchar)
from (
select 1 as d
union all
select 2
union all
select 3
union all
select 4
union all
select 5
union all
select 6
union all
select 7
union all
select 8
union all
select 9
union all
select 10
union all
select 11
union all
select 12
union all
select 13
) as t
where datepart(weekday,@s+'-'+cast(d as varchar))=2
order by d desc
pandayi 2007-06-20
  • 打赏
  • 举报
回复
6月的第二个周一应该是4号吧

我觉得
declare @s varchar(20)
set @s='2007-7'
set @s=@s+'-1'
select dateadd(dd,9-DATEPART(dw,@s),@s)

这个贴好.学习了。

34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧