Skip to content
Advertisement

date_trunc month in SQL Server

I want to extract the “month” from the date_contact column. I tried select dateadd(mm, datediff(mm,0, date_contact), 0) from cohort and select cast(date_contact As Date). I received result that is same as date from the first method. And for the second method I got error message: date_contact is not a valid name.

enter image description here

Advertisement

Answer

select datepart(mm,date_contact) from cohort

aka..

select month(date_contact) from cohort

or…

select datename(mm,date_contact) from cohort
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement