sql-server - 我需要一个 SQL 服务器 Func 来计算一年中一周的完整日期
问题描述
我需要计算到一串 dd-MM-yyyy
来自 wwyy 字符串(我需要一周的第一天或一周中的任何其他天)
例如:现在我们在 18 周的第 42 周,所以如果我输入 4218,我将得到 15-10-2018 或 14-10-2018
BR,伊丹
解决方案
declare @input char(4) set @input = 4218
SET DATEFIRST 1
declare @wk int set @wk = cast(SUBSTRING(@input,1,2) as int)
declare @yr int set @yr = 2000 + cast(SUBSTRING(@input,3,2) as int)
select dateadd (week, @wk, dateadd (year, @yr-1900, 0)) - 4 -
datepart(dw, dateadd (week, @wk, dateadd (year, @yr-1900, 0)) - 4) + 1
推荐阅读
- image - ffmpeg:从 .mp3 和 .jpg 创建 .mp4
- python - 在尝试绘制昼夜图时面临这个非常特殊的错误
- rust - 在 Rust 宏中,如何跟随符号获取另一个函数定义的令牌流?
- flutter - 为什么在颤动中使用 Colors.color_name[value] 设置背景颜色时显示错误?
- react-native - 在 React Native 中安装模块时出错
- api - 无法使用Api拦截python返回response.url
- javascript - 签名板
- python - 如何在ubuntu上导入库usocket
- wordpress - 添加文章分享按钮 - wordpress 帖子网格
- angular - ejs-grid 获取对话框更改值