SQL Server > Built in functions

DateName function in SQL Server

How to get name part of a particular date in Sql Server?


To get name of a particular date, we can use DATENAME function in Sql Server.

select DATENAME(dw, '2015-05-19 12:59:30')

Output

Tuesday

This function can also be used to get Month name, year, day of the month etc. as shown below. Pass desired parameter in place of "dw" to get required details.

Parameter ValueDescription
yy 2015 Yes
qq 2 Quarter
mm May Month name
dy 139 Day of the year
dd 19 Day of the month
wk 21 Week of the year
dw Tuesday Day name of the week
hh 12 Hour of the date time passed
n 59 Minute of the date time passed
ss 30 Second of the date time passed

Similarly, we can also pass ms for milli seconds, mcs for micro seconds, ns for nano seconds.

To get the integer part of value from the date, we can use DATEPART function in Sql Server.

 Views: 6400 | Post Order: 67



Write for us






Hosting Recommendations