Mssql function DATENAME
Copy codeThe Code is as follows:
Syntax
DATENAME (datepart, date)
Parameters
Datepart
Is part of the returned date. The following table lists all valid datepart parameters. The user-defined equivalent variable is invalid.
Date
Is an expression that can be parsed to time, date, smalldatetime, datetime, datetime2, or datetimeoffset values. Date can be an expression, column expression, user-defined variable, or string text.
To avoid uncertainty, use a four-digit year. For information about the two-digit year, see the two digit year cutoff option.
Return type
Nvarchar
Return Value
Each datepart and Its abbreviation return the same value.
The returned value varies depending on the LANGUAGE environment SET by the set language and the default LANGUAGE for logon. If date is a string of some formats, the return value is determined by set dateformat. When the date is a column expression of the date or time data type, set dateformat does not affect the return value.
How to get the current date, format with a short horizontal line, without a horizontal line, how to get the current time.
How to get the month, quarter, the day of the year...
Copy codeThe Code is as follows:
Select convert (varchar (10), getdate (), 120) -- current year month day, Example: 2013-11-19
Select convert (varchar (10), getdate (), 112) -- current year, month, and day, Example: 20131119
Select convert (varchar (10), getdate (), 108) -- current year month day, Example: 20: 28: 36
Select datename (day, getdate () -- number of the current month
Select datename (month, getdate () -- month
Select datename (quarter, getdate () -- quarter
Select datename (dayofyear, getdate () -- the day of the year
Select datename (week, GETDATE () -- week of the year
Select datename (weekday, GETDATE () -- day of the week
Select datename (hour, GETDATE () -- current time, in the 24-hour format
Select datename (minute, GETDATE () -- get the current number of minutes
Select datename (second, GETDATE () -- returns the current number of seconds.
Select datename (millisecond, GETDATE () -- millisecond