Sql server: get month name or number from date

In this article I am going to explain how to get month name or number from date using Sql server.

Description:
We can get the month name using datename and format function and month number using datepart function of sql.

Month name example:

select [Month name]=datename(mm,@currentdate)
select [Month name]=datename(MONTH,@currentdate)
SELECT [Month name]= FORMAT(@currentdate,'MMMM')

Output:
Month name
February

Month number example:

select [Month No.]=datepart(mm,@currentdate)

Output:

Month No.
2


Post a Comment

0 Comments