我如何转换@dateb:
SET @dateb = dateadd(month, datediff(month, 0, getdate()) - 3, 0)
Run Code Online (Sandbox Code Playgroud)
2014-04-04作为日期返回到整数201404
谢谢
Bob*_*mes 21
在 2012 或更高版本上,您可以使用该format函数获取年和月,然后将其转换为 int。
在 2012 之前的版本上,您可以使用该convert函数进行格式化,然后转换为 int。
declare @dateb datetime
set @dateb = getdate()
select cast(format(@dateb,'yyyyMM') as int) --2012 or higher
select cast(convert(varchar(6),@dateb,112) as int) -- all versions
Run Code Online (Sandbox Code Playgroud)
Aar*_*and 17
也许更整洁一点:
SELECT YEAR(@dateb)*100 + MONTH(@dateb);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
184784 次 |
| 最近记录: |