LISTING 2: Using Date Components to Produce Values for the DATENAME() and DATEPART() Functions SELECT ' Year:' AS 'Date Component' , DATEPART(year, getdate()) AS 'DATEPART()' , DATENAME(year, getdate()) AS 'DATENAME()' , 'YEAR(): ' + CONVERT(varchar(4), YEAR(getdate())) AS 'Synonym Function' UNION ALL SELECT ' YY:', DATEPART(yy, getdate()) , DATENAME(yy, getdate()) , 'YEAR(): ' + CONVERT(varchar(4), YEAR(getdate())) UNION ALL SELECT ' YYYY:' , DATEPART(yyyy, getdate()) , DATENAME(yyyy, getdate()) , 'YEAR(): ' + CONVERT(varchar(4), YEAR(getdate())) UNION ALL SELECT ' Quarter:' , DATEPART(quarter, getdate()) , DATENAME(quarter, getdate()) , 'n/a' UNION ALL SELECT ' Month:' , DATEPART(month, getdate()) , DATENAME(month, getdate()) , 'MONTH(): ' + CONVERT(varchar(4), MONTH(getdate())) UNION ALL SELECT ' DayOfYear:' , DATEPART(dayofyear, getdate()) , DATENAME(dayofyear, getdate()) , 'n/a' UNION ALL SELECT ' Day:' , DATEPART(day, getdate()) , DATENAME(day, getdate()) , 'DAY(): ' + CONVERT(varchar(4), DAY(getdate())) UNION ALL SELECT ' Week:' , DATEPART(week, getdate()) , DATENAME(week, getdate()) , 'n/a' UNION ALL SELECT ' Weekday:' , DATEPART(weekday, getdate()) , DATENAME(weekday, getdate()) , 'n/a' UNION ALL SELECT ' Hour:' , DATEPART(hour, getdate()) , DATENAME(hour, getdate()) , 'n/a' UNION ALL SELECT ' Minute:' , DATEPART(minute, getdate()) , DATENAME(minute, getdate()) , 'n/a' UNION ALL SELECT ' Second:' , DATEPART(second, getdate()) , DATENAME(second, getdate()) , 'n/a' UNION ALL SELECT ' Millisecond:' , DATEPART(millisecond, getdate()) , DATENAME(millisecond, getdate()) , 'n/a' GO