Get month and year from a datetime in SQL Server 2005

后端 未结 20 1451
[愿得一人]
[愿得一人] 2020-12-12 15:39

I need the month+year from the datetime in SQL Server like \'Jan 2008\'. I\'m grouping the query by month, year. I\'ve searched and found functions like datepart, convert, e

相关标签:
20条回答
  • 2020-12-12 16:39
    select 
    datepart(month,getdate()) -- integer (1,2,3...)
    ,datepart(year,getdate()) -- integer
    ,datename(month,getdate()) -- string ('September',...)
    
    0 讨论(0)
  • 2020-12-12 16:39
    cast(cast(sq.QuotaDate as date) as varchar(7))
    

    gives "2006-04" format

    0 讨论(0)
提交回复
热议问题