Database Reference
In-Depth Information
MM/CCYY 2nd Thursday 4th Thursday
01/2014 2014-01-09 2014-01-23
02/2014 2014-02-13 2014-02-27
03/2014 2014-03-13 2014-03-27
04/2014 2014-04-10 2014-04-24
05/2014 2014-05-08 2014-05-22
06/2014 2014-06-12 2014-06-26
07/2014 2014-07-10 2014-07-24
08/2014 2014-08-14 2014-08-28
09/2014 2014-09-11 2014-09-25
10/2014 2014-10-09 2014-10-23
11/2014 2014-11-13 2014-11-27
12/2014 2014-12-11 2014-12-25
6.18. Performing Leap-Year Calculations
Problem
A date calculation must account for leap years. For example, the length of a month or
a year depends on whether the date falls in a leap year.
Solution
Know how to test whether a year is a leap year, and factor the result into your calculation.
Discussion
Date calculations are complicated by the fact that months differ in length. An additional
twist is that February has an extra day during leap years. This recipe shows how to
determine whether any given date falls within a leap year and how to take leap years
into account when determining the length of a year or month.
Determining whether a date occurs in a leap year
To determine whether a date d falls within a leap year, obtain the year component using
YEAR() and test the result. The common rule-of-thumb test for leap years is “divisible
by four,” which you can test using a modulo operation:
YEAR(d) % 4 = 0
However, that test is not technically correct. (For example, the year 1900 is divisible by
four, but is not a leap year.) For a year to qualify as a leap year, it must satisfy both of
these constraints:
• The year must be divisible by four.
• The year cannot be divisible by 100, unless it is also divisible by 400.
Search WWH ::




Custom Search