29.1. Temporal Math

Almost every SQL implementation has a DATE data type, but the functions available for that data type vary quite a bit. The most common ones are a constructor that builds a date from integers or strings; extractors to pull out the month, day, or year; and some display options to format output.

You can assume that your SQL implementation has simple date arithmetic functions, although with different syntax from product to product, such as:

1.A date plus or minus a number of days yields a new date
2.A date minus a second date yields an integer number of days

Table 29.1 shows the valid combinations of <datetime> and <interval> data types in Standard SQL:

Table 29.1. Valid Combinations of Temporal Data Types in Standard SQL
<datetime> ...

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.