Use of datepart () Functions

Source: Internet
Author: User

 
* The datepart () function allows you to conveniently retrieve all parts of the period.
* Date: 18:15:36. 513
* YY: 2006 of the year
* Mm: 7 months
* DD: 2 days in the month
* DY: 183 days in the year
* WK: week 27 in the year
* DW: The day in the week.
* QQ: Quarter 3 of the year
* Hh: 18 hours
* Mi: 15 minutes
* Ss: 36 seconds
* The following simple statements demonstrate the obtained results:
*/

Select getdate ()
Select datepart (mm, getdate ())
Select datepart (YY, getdate ())
Select datepart (DD, getdate ())
Select datepart (dy, getdate ())
Select datepart (wk, getdate ())
Select datepart (DW, getdate ())
Select datepart (QQ, getdate ())
Select datepart (HH, getdate ())
Select datepart (MI, getdate ())
Select datepart (SS, getdate ())

Select datediff (DD, getdate (), '2014/1/123') -- calculates the number of days from today
Select datediff (mm, getdate (), '2014/1/123') -- calculates the number of months from today till.
Select datename (mm, getdate () -- Obtain the month of today in the form of a string instead of a number (07)

Select dateadd (DD, 30, getdate () -- add 30 days to the current date
Select dateadd (mm, 3, getdate () -- add 3 months to the current date
Select dateadd (YY, 1, getdate () -- add one year to the current date

Select dateadd (QQ, datediff (QQ, 0, getdate (), 0) -- get the first day of this quarter
Select dateadd (mm,-3, dateadd (QQ, datediff (QQ, 0, getdate (), 0) -- get the first day of the previous master and quarter

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.