Month name and Weekday name in SQL Server

Ever wonder how you can get Month name and Weekday name in SQL Server? You need not hardcode and write any logic but you can use the function datename instead of datepart. Quick example on how it works…

declare @mystring varchar(10)
set @mystring = '20150918'

select datename(year, @mystring) as myYEAR
select datename(month, @mystring) as myMonthName
select datepart(month, @mystring) as myMonth
select datename(week, @mystring) as myWeekOfTheYEar
select datename(day, @mystring) as myDate
select datename(weekday, @mystring) as myWeekName
select datepart(weekday, @mystring) as myWeekdayNumber
--
--

FYI:
monthname_WeekdayName

Advertisements
This entry was posted in Productivity, SQL Query, SQL Server and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s