SQL Scalar Function-----Date function DateDiff (), Day (), month (), year ()

Source: Internet
Author: User
Tags scalar

Select Day (createtime) from Life_unite_product--the days value of the Take time field

Select Month (createtime) from Life_unite_product--take the month value of the Time field

Select year (createtime) from Life_unite_product--the yearly value of the Fetch time field

Select DATEPART (yy,createtime) from Life_unite_product--take the year value of the Time field

Select DATEPART (qq,createtime) from Life_unite_product--take the quarter value of the Time field

Select DATEPART (mm,createtime) from Life_unite_product--take the month value of the Time field

Select DATEPART (dy,createtime) from Life_unite_product--Take time field is the day ordinal of that year

Select DATEPART (dd,createtime) from Life_unite_product--the day value of the Fetch time field

Select DATEPART (wk,createtime) from Life_unite_product--Take the Time field is the first week of that year

Select DATEPART (dw,createtime) from Life_unite_product--Take the Time field is the first weekday of the Week of that year (working days are calculated from Sunday)

Select DATEPART (hh,createtime) from Life_unite_product--the time-out value of the Fetch field

Select DATEPART (mi,createtime) from Life_unite_product--Take the minute value of the Time field

Select DATEPART (ss,createtime) from Life_unite_product--takes the seconds value of the Time field

Select DATEPART (ms,createtime) from Life_unite_product--take the millisecond value of the Time field

Select DATEADD (yy,-1,createtime) from life_unite_product----fetch Time field (year is reduced by 1)

Select DATEADD (mm,3,createtime) from life_unite_product----fetch Time field (month is added 3)

Select DATEADD (dd,1,createtime) from life_unite_product----fetch time field (Day added 1)

Select DATEDIFF (Yy,createtime,getdate ()) from life_unite_product--year difference from current date

Select DATEDIFF (Mm,createtime,getdate ()) from Life_unite_product--The month difference from the current date

Select DATEDIFF (Dd,createtime,getdate ()) from Life_unite_product--the difference in the number of days from the current date

Select DATEDIFF (Mi,createtime,getdate ()) from Life_unite_product--the difference in minutes from the current date

Select Datename (yy,createtime) from Life_unite_product--take the year value of the Time field

Select Datename (mm,createtime) from Life_unite_product--take the month value of the Time field

Select Datename (dd,createtime) from Life_unite_product--the day value of the Fetch time field

Select GETDATE ()--Take the current time

Date function

1. Day (date_expression)

Returns the date value in Date_expression

2. Month (date_expression)

Returns the month value in Date_expression

3. Year (date_expression)

Returns the year value in Date_expression

4, DATEADD ()

DATEADD (,,)

Returns the new date specified by date plus the specified extra date interval number. The parameter "DatePart" takes the following values:

5, DATEDIFF ()

DATEDIFF (,,)
Returns the DATEPART difference between the two specified dates, that is, the date2 exceeds the value of date1, and the resulting value is an integer value with a positive sign.

6, Datename ()

Datename (,)
Returns the specified part of the date as a string in this section. specified by DatePart.

7, DATEPART ()

DATEPART (DATEPART, date)

Returns the specified part of the date as an integer value. This section is specified by DatePart.

DATEPART (dd, date) is equivalent to day (date)

DATEPART (mm, date) equals month (date)

DATEPART (yy, date) is equivalent to year (date)

The following table lists the DATEPART options and the abbreviations recognized by the SQL Server Compact Edition:

Date part         abbreviation  
Year              yy, yyyy 

Quarterly              QQ, q 

Month             mm, m 

One day of the year     Dy, y 

Date             DD, d 

Week             wk, ww 

Weekday *          DW

Hours              hh 

minutes             mi, n  

Seconds               SS, s 

milliseconds             ms

SQL Scalar Function-----Date function DateDiff (), Day (), month (), year ()

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.