SQL datename usage

Source: Internet
Author: User
Tags month name

Transact-SQL reference

Datename

Returns the string representing the specified date part of the specified date.

Syntax

DATENAME ( datepart , date )

Parameters

Datepart

Is a parameter that specifies the date part to be returned. The following table lists the dates and abbreviations recognized by Microsoft SQL Server.

Date Abbreviations
Year YY, yyyy
Quarter QQ, Q
Month Mm, m
Dayofyear Dy, y
Day DD, d
Week Wk, WW
Weekday DW
Hour HH
Minute Mi, n
Second SS, S
Millisecond MS

Weekday(DW) The date part returns the day of the week (Sunday, Monday, etc ).

YesDatetimeOrSmalldatetimeValue or date format string expression. For the date after January 1, January 1, 1753DatetimeData type. The earlier date is stored as character data. When you enterDatetimeAlways put the value in quotation marks. BecauseSmalldatetimeOnly accurate to minutes, so when usingSmalldatetimeThe second and millisecond values are always 0. For more information about the specified date, see datetime and smalldatetime. For more information about the time value, see time format.

If only the last two digits of the year are specified, the value is less than or equalTwo digit year cutoffThe last two-digit value of the configuration option value is in the same century as the end year. The last two-digit number greater than the value of this option is in the century before the end of the century. For example, ifTwo digit year cutoffIs 2050 (default), then 49 is interpreted as 2049,50 is interpreted as 1950. To avoid blurring, use a four-digit year.

Return type

Nvarchar

Note

SQL Server automaticallyDatetimeValues are converted as needed. For exampleDatetimeWhen the value is compared.

Example

In this example, the month name is extracted from the date returned by getdate.

SELECT DATENAME(month, getdate()) AS 'Month Name'

The following is the result set:

Month Name------------------------------February

See

 

Cast and convert

Data Type

Date and Time Functions



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.