Skip to content
Advertisement

SQL Format(‘MMMM’) does not work in SQL Server 2008

I had this query

select 
    format([time], 'MMMM') as 'Month', 
    count([time]) as 'Application Usage', 
    count([time]) as 'Application Usage' 
from 
    UserLogs UL 
where 
    [time] >= Dateadd(Month, Datediff(Month, 0, DATEADD(m, -6, current_timestamp)), 0) 
    and Ul.UserId = @user 
group by
    format([time],'MMMM')

However I migrated to a server using SQL Server 2008 and I get this error:

‘format’ is not a recognized built-in function name

What can I use to replace this format function?

Advertisement

Answer

This is a feature with SQL Server 2012 and higher. Try DATENAME(MONTH,[time]).

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement