The syntax goes like:
DATENAME ( datepart ,date )
Where :
datepart - specifies the part of the date to return
date - datetime or smalldatetime expression
USAGE:
DECLARE @Dt datetime
SET @Dt = '2008-04-15 8:34:54.713'
SELECT DATENAME(year, @Dt) as 'Year'
-- Returns 2008
SELECT DATENAME(quarter, @Dt) as 'Quarter'
-- Returns 2
SELECT DATENAME(month, @Dt) as 'Month'
-- Returns April
SELECT DATENAME(dayofyear, @Dt) AS 'Day of Year';
-- Returns 106
SELECT DATENAME(day, @Dt) AS 'Day';
-- Returns 15
SELECT DATENAME(week, @Dt) AS 'Week';
-- Returns 16
SELECT DATENAME(weekday, @Dt) AS 'Weekday';
-- Returns Tuesday
SELECT DATENAME(hour, @Dt) AS 'Hour';
-- Returns 8
SELECT DATENAME(minute, @Dt) AS 'Minutes';
-- Returns 34
SELECT DATENAME(second, @Dt) AS 'Seconds';
-- Returns 54
SELECT DATENAME(millisecond, @Dt) AS 'Milliseconds';
-- Returns 713
No comments:
Post a Comment