我需要 SQL Server 中日期时间的月+年,例如“2008 年 1 月”。我按月、年对查询进行分组。我搜索并找到了诸如 datepart、convert 等函数,但它们似乎都对此没有用处。我在这里错过了什么吗?有这个功能吗?
最佳答案
select
datepart(month,getdate()) -- integer (1,2,3...)
,datepart(year,getdate()) -- integer
,datename(month,getdate()) -- string ('September',...)
关于sql - 从 SQL Server 2005 中的日期时间获取月份和年份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45535/