MSSQL function Datename
Copy Code code as follows:
Grammar
Datename (datepart, date)
Parameters
DatePart
is part of the returned date. The following table lists all the valid datepart parameters. User-defined variable equivalents are not valid.
Date
is an expression that resolves to a time, date, smalldatetime, DateTime, datetime2, or DateTimeOffset value. Date can be an expression, a column expression, a user-defined variable, or a string literal.
To avoid uncertainty, use a four-digit year. For information about two-digit years, see the two digit year cutoff option.
return type
nvarchar
return value
Each datepart and its initials return the same value.
The return value varies depending on the locale used by the set LANGUAGE and the default language of the login. If date is a string literal in some format, the return value is determined by the set DateFormat. The set DateFormat does not affect the return value when a column expression of date or time data type is present.
How to get the current date, formatted with a dash, without a horizontal line, and how to get the current time.
How to get the month, quarter, day of the year ...
Copy Code code as follows:
SELECT CONVERT (varchar (), GETDATE (), 120)--Current month and day, example:2013-11-19
SELECT CONVERT (varchar (), GETDATE (), 112)--Current month and day, example:20131119
SELECT CONVERT (varchar (), GETDATE (), 108)--Current month and day, example:20:28:36
SELECT datename (Day, GETDATE ())--Date of the month
SELECT datename (month, GETDATE ())--month
SELECT datename (Quarter, GETDATE ())--Quarterly
SELECT datename (DayOfYear, GETDATE ())--Day of the year
SELECT Datename (Week,getdate ())--the first few weeks of the year
SELECT Datename (Weekday,getdate ())--Day of the week
SELECT Datename (Hour,getdate ())--current time, 24-hour
SELECT Datename (Minute,getdate ())--Take the current number of minutes
SELECT Datename (Second,getdate ())--Take the current number of seconds
SELECT Datename (Millisecond,getdate ())--milliseconds