Get Day Name / DATENAME in SQL
DateName is mainly used to get the Name of the date for the given Date like (Sunday, Monday,...), also this is used to following purpose.1. Get the Day Name
2. Get the Month Name
3. Get the Week of the year
4. Get the Quarter of the Year
5. Get the Day of the Year
1) Get the Day Name
This is used to get the day name from the given date (Sunday, Monday, Tuesday,...).
Example
SELECT DATENAME(DW,'01/7/2013') as DayName
Output
2) Get the Month Name
This is used to get the Name of the month from the given date (January, February, March, April, May,... )
Example
SELECT DATENAME(MONTH,'01/7/2013') as MonthName
Output
3) Get the Week of the year
Find the number of the week in the given year.
Example
SELECT DATENAME(WEEK,'01/7/2013') as WeekOfYear
Output
4) Get the Quarter of the Year
Find number of the quarter from the given year.
Example
SELECT DATENAME(QQ,'04/7/2013') as Quarter
Output
5) Get the Day of the Year
Count and display the number of the day from the given date.
Example
SELECT DATENAME(DY,'1/20/2013') as DayOfYear
Output
0 comments:
Post a Comment