O'Reilly logo

Joe Celko's Thinking in Sets: Auxiliary, Temporal, and Virtual Tables in SQL by Joe Celko

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

9.5. Calendar Tables

Calendar tables are necessary because the current calendar is so irregular that you cannot reasonably compute events. Yes, there is a 19-year cycle (the Metonic cycle, named after the fifth-century Greek astronomer, Meton) in which the days of the week will repeat and you could use this to create a self-updating view if you need to use the days of the week. But it is just as easy to have a 100-year calendar in a single short table and use it.

9.5.1. Day of Week via Tables

The classic method for computing the day of the week in the Common Era calendar is a bit complicated. Here is the algorithm:

  1. Take the last two digits of the year. In our example, this is 82.

  2. Do integer division by 4 on the decade (two digits of the year). ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required