SQL datename \ datepart returns a string that indicates the specified datepart of the specified date.

Source: Internet
Author: User
1. Syntax
 
Datepart (datepart, date)
Parameters
Datepart

YesIntegerIs part of the date (date or time value. The following table lists all valid datepart parameters. The user-defined equivalent variable is invalid.

Datepart

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

Microsecond

MCS

Nanosecond

NS

TZOFFSET

TZ

Iso_week

Isowk,Isoww

Date

Is an expression that can be parsedTime,Date,Smalldatetime,Datetime,Datetime2OrDatetimeoffsetValue. 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.

 

 

 

2. When datename and datepart are used to set datepart to weekday, they are displayed differently. And it depends on the day of the week.

CodeAs follows:

View code 1 Set Datefirst 1
2 Select datename (DW, getdate ()) As Datename,
3 Datepart (DW, getdate ()) As Datapart

 

The running result is as follows:

 

Above, I set Monday as the first day of a week. Therefore, 3 in datepart corresponds to 3 in Wednesday.

 

 

 

Refer to the following: msdn-datename

 

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.