// data type reference

INTERVAL YEAR TO MONTH

A year-to-month interval counts calendar months: 3 years, 6 months. It is the only interval that respects calendar length - a month is a month, not 30 days - and only Oracle gives it a real column type.

Missing in
None of the five
Gotchas
4 listed

Engine by engine

Whole months as a duration. Oracle stores it natively (INTERVAL YEAR TO MONTH, 5 bytes), PostgreSQL folds it into its 16-byte INTERVAL, and the other three engines store an integer month count.

INTERVAL YEAR TO MONTH in SQL Server, PostgreSQL, MySQL, SQLite and Oracle: type name, storage and notes
Motor Tipo Almacenamiento Notas
SQL Server int (month count) 4 bytes No INTERVAL type. Store total months in an INT and rebuild dates with DATEADD(MONTH, months, d).
PostgreSQL INTERVAL 16 bytes One INTERVAL covers both interval families, with separate months, days and microseconds fields.
MySQL int (month count) 4 bytes INTERVAL exists only as expression syntax (SELECT INTERVAL '1' MONTH + d), not as a column type.
SQLite INTEGER 1 to 8 bytes No interval support. Store the month count and add it with date(d, '+N months').
Oracle INTERVAL YEAR TO MONTH 5 bytes INTERVAL '3-6' YEAR TO MONTH; year precision defaults to 2 digits and goes up to 9.

Gotchas

Where the engines disagree. These tend to surface as bugs during a migration or a port.

  1. Oracle splits intervals into YEAR TO MONTH and DAY TO SECOND because you cannot convert between them: 1 month is not 30 days. Choosing the wrong family loses calendar arithmetic.
  2. PostgreSQL has a single INTERVAL for both families, kept as separate months, days and microseconds. Adding them to dates differs (Jan 31 + 1 month is Feb 28), yet comparison treats a month as 30 days: interval '1 month' = interval '30 days' is true.
  3. Neither MySQL nor SQL Server has an interval column type. MySQL has INTERVAL only as expression syntax (DATE_ADD(d, INTERVAL 3 MONTH)); SQL Server has no INTERVAL at all, only DATEADD.
  4. Oracle's default year precision is 2, so INTERVAL '100-0' YEAR TO MONTH fails until you write INTERVAL '100-0' YEAR(3) TO MONTH.

Common questions

Why are there two interval types?

Because months and days do not convert cleanly: month lengths vary with the calendar. ISO SQL defines YEAR-MONTH intervals and DAY-SECOND intervals as separate families that cannot be mixed in one value.

How do I store a subscription length in SQL Server?

Store the number of months in an INT and compute the end date with DATEADD(MONTH, @months, @start). That keeps month-end behavior consistent instead of guessing 30 days.

How many bytes is INTERVAL YEAR TO MONTH?

5 bytes in Oracle. PostgreSQL's combined INTERVAL is 16 bytes; integer-month emulation is 4 bytes everywhere else.

// map types before you move data

Map a type to the other four engines

The free type converter maps a type from one engine to its closest equivalent in the others and says where storage, precision or behaviour differ. The desktop app does the same mapping while you edit.