SQL, how to get the number of months, weeks, and days before two dates

Source: Internet
Author: User

1. Get the number of months, weeks, and days between two dates syntax

   --1. Get the number of months, weeks, and days between two dates    --1.1) Declaring parameters    Declare @startDate varchar( -)    Declare @endDate varchar( -)    --1.2) Get the number of months directly on the two date    Select DATEDIFF(MM,@startDate,@endDate)     --1.3) Get the number of months directly on the two date    Select DATEDIFF(WW,@startDate,@endDate)     --1.4) Get the number of months directly on the two date    Select DATEDIFF(DD,@startDate,@endDate)

2. Test Cases

    --2. Test Cases    --2.1) Gets the number of months directly from the specified date and the current date    Select DATEDIFF(MM,'2017-08-12 11:12:23',GETDATE()) asnumber of months--2.2) Gets the number of weeks directly from the specified date and the current date    Select DATEDIFF(WW,'2017-08-12 11:12:23',GETDATE()) asWeek number--2.3) Gets the number of months directly from the specified date and the current date    Select DATEDIFF(DD,'2017-08-12 11:12:23',GETDATE()) asDays

3. Test results

SQL, how to get the number of months, weeks, and days before two dates

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.