SQL 将周数转换为日期 (dd/MM) [英] SQL Convert Week Number to Date (dd/MM)

查看:56
本文介绍了SQL 将周数转换为日期 (dd/MM)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 SQL-Server 中的周数(例如:21)转换为 中的日期(从该周的星期一开始)dd/MM 格式.

I am trying to convert the week number (for example: 21) in SQL-Server to the date (from the Monday of that week) in dd/MM format.

我在网上搜索过,但似乎找不到我可以使用的任何东西.

I have searched online but cannot seem to find anything that I could use.

这是我能做的吗?

感谢任何帮助或建议.

提前致谢.

推荐答案

试试这个,

declare @wk int  set @wk = 21
declare @yr int  set @yr = 2016

select dateadd (week, @wk-1, dateadd (year, @yr-1900, 0)) - 4 -
       datepart(dw, dateadd (week, @wk-1, dateadd (year, @yr-1900, 0)) - 4) + 1

或者试试这个方法

declare @wk int  = 21

select dateadd(week,@wk-1, DATEADD(wk, DATEDIFF(wk,-1,DATEADD(yy, DATEDIFF(yy,0,getdate()), 0)), 0)) 

这篇关于SQL 将周数转换为日期 (dd/MM)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆