SQL statement used to determine whether the year of a given date is a leap year

Source: Internet
Author: User
SQL statement used to determine whether a given date is in a leap year -- declare @ datedatetime based on the total number of days of the year; set @ dategetdate () selectcasedatediff (day, dateadd (year, datediff (year, 0, @ date), 0), dateadd (year, 1 + datediff (year, 0, @ date), 0) & nbsp SQL statement used to determine whether the year of a given date is a leap year
-- Judge based on the total number of days of the year
Declare @ date datetime;
Set @ date = getdate ()
Select case datediff (day, dateadd (year, datediff (year, 0, @ date), 0), dateadd (year, 1 + datediff (year, 0, @ date ), 0 ))
When 365 then 'Year' else 'Year' end
-- Judge based on the number of days in February
-- Add two months to the last day of the last year of the date, that is, the last day of the year, January 1, February.
Select case day (dateadd (month, 2, dateadd (year, datediff (year, 0, @ date),-1) when 28 then 'Year' else 'Year' end
Go

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.