SQL Time Date function

Source: Internet
Author: User

getdate () function

Returns the current date and time of the system in the default format of datetime

Syntax format: getdate ()

Year () Month () Day () function

Returns the year, month, and date value in Date_expression

Syntax format: year/month/day (date_expression datetime/varchar) Returns int

Example: Year (GETDATE ()), year (' 2016-05-01 ')

datename () function

Returns the specified part of a date as a string

Syntax format: datename (datepart,date_expression)

Example: Datename (Month,getdate ()), Datename (year, ' 2016-05-01 ')

datepart () function

Returns the specified part of a date as an integral type

Syntax format: DATEPART (datepart,date_expression)

DateAdd () function

Returns the new date specified by date plus the specified extra date interval number

Syntax format: DATEADD (datepart,number,date)

Cases:

Add 2 months on the specified date

DATEADD (mm,2, ' 2016-05-11 ') 2016-07-11

DATEADD (Mm,2,getdate ())

Minus 2 months on a specified date

DATEADD (mm,-2, ' 2016-05-11 ')

DATEADD (Mm,-2,getdate ())

DateDiff () function

Returns the datepart difference between the specified two dates, that is, the gap value of StartDate and EndDate, and the result is a signed integer value

Syntax format: DateDiff (Datepart,startpart,endpart)

Example: DATEDIFF (DD, ' 2016-05-01 ', ' 2016-07-10 ') returns 70, the number of days gap value is 70

DATEDIFF (MM, ' 2016-05-01 ', ' 2016-07-10 ') returns 2, month gap value is 2

SQL Time Date function

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.