Mssql function DATENAME usage example (obtain the SQL statement for the day of the current year/year)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.