The similarities and differences between the DATENAME function and the DATEPART function in SQL functions:
Syntax: Datename ( datepart ,date ) and datepart ( datepart , date )
Description: The Datename function obtains the name, according to the different SQL engine version different and obtains the difference result;
Gets the name of the time, such as Get Week: Datename (wk,date) returns, the day of the week, such as Sunday,monday, and DATEPART (wk,date) returns the value, such as Monday, returns 2, Sunday is 1,
The same datename(datepart , date ) can obtain the monthly score, while datepart ( datepart , date ) /c11> to get the monthly value of the corresponding values, such as January 1.
When the name value of the time equals the number, two functions get the same value. such as: Datename (Dy,getdate ()) =datepart (Dy,getdate ()).
The following are the desirable values for the first parameter of the two function:
Take year: yy, yyyy;
Month Taken: m,mm
Season: Q,QQ
Take weeks: DW
Weeks: wk,w
Take the number of days of the year: DY
Day taken from date: DAY,DD
Time, minutes, seconds: hh,mi,ss
Description:weekday (DW) Date part returns the day of the week (Sunday, Monday, etc.). Quarter (QQ) returns the quarterly value, the first quarter of the year. DayOfYear (Dy) returns the day ordinal of a year.
Example:
In most SQL SERVER English versions (as well as some traditional versions),
SELECT datename (month, GETDATE ()) get January;
In the Simplified Chinese version, you get: 01
and select DATEPART (Month,getdate ()) gets 1 in all versions
The same is true when you take the value of a week.
In these versions, the use of the Datename function in the English version will get the most original value.