29.2. Personal Calendars

One of the most common applications of dates is to build calendars that list upcoming events or actions to be taken by their user. People have no trouble with using a paper calendar to trigger their own actions, but the idea of having an internal calendar as a table in their database is somehow strange. Programmers seem to prefer to write a function that calculates the date and matches it to events.

It is easier to create a table for cyclic data than people initially think. The months and days of the week within a year repeat themselves in a cycle of 28 years. A table of just more than 10,000 rows can hold a complete cycle. The cycle has to repeat itself every 400 years, so today is on the same day of the week that it ...

Get Joe Celko's SQL for Smarties, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.