DATENAME () function can use for date and time related operation in Sql server called DATENAME (). The DATENAME () returns a character string representing the specified datepart of the specified.date.
DATENAME() Syntax
DATENAME(datepart,datetime)Datepart: Is the parameter that specifies the part of the date to return.
Datetime: Is an expression that returns a datetime or smalldatetime value.
Examples
DECLARE @Today DATETIMESET @Today=GETDATE() --'15-Dec-2010' SELECT DATENAME(month, @Today) -- Get the month from dateSELECT DATENAME(mm, @Today )SELECT DATENAME(m, @Today)------------Output-----------------------------------------------------------------------------December SELECT DATENAME(dayofyear, @Today) -- select day of year, its return current day from 1 of jan SELECT DATENAME(dy,@Today)SELECT DATENAME(y, @Today)------------Output------------------------------------------------------------------------------349 SELECT DATENAME(day, @Today) -- select the day of the monthSELECT DATENAME(dd, @Today)SELECT DATENAME(d, @Today)------------Output------------------------------------------------------------------------------15 SELECT DATENAME(week, @Today) -- get week numbre of the yearSELECT DATENAME(wk,@Today)SELECT DATENAME(ww, @Today)------------Output------------------------------------------------------------------------------51 SELECT DATENAME(hour, @Today) -- select the current hour for nowSELECT DATENAME(hh, @Today)------------Output------------------------------------------------------------------------------13 SELECT DATENAME(minute, @Today) -- select the current minute for nowSELECT DATENAME(mi, @Today)SELECT DATENAME(n, @Today)------------Output------------------------------------------------------------------------------45 SELECT DATENAME(second , @today) -- select the current seocnd for nowSELECT DATENAME(ss, @today)SELECT DATENAME(s, @today)------------Output------------------------------------------------------------------------------34 SELECT DATENAME(millisecond , @today) -- select the current milliseconds for nowSELECT DATENAME(ms, @today)------------Output------------------------------------------------------------------------------340Have a nice day... 'N happy Coding :)
No comments:
Post a Comment