Datetime Interval Expressions - IBM DB2 to MariaDB Migration

In DB2, you can use interval expressions to add a specified number of units to a datetime value:

IBM DB2:

  -- Add 3 months to the current date
  SELECT CURRENT_DATE + 3 MONTHS FROM sysibm.sysdummy1;

MariaDB also supports interval expressions, requiring the INTERVAL keyword and singular time units (e.g., DAY instead of DAYS):

MariaDB:

  -- Add 3 months to the current date
  SELECT CURRENT_DATE + INTERVAL 3 MONTH;

Datetime interval expressions:

DB2 Interval Unit MariaDB Interval Unit
1 MONTH MONTHS Interval in months MONTH
2 DAY DAYS Interval in days DAY
3 MINUTE MINUTES Interval in minutes MINUTE
4 SECOND SECONDS Interval in seconds SECOND

Examples:

DB2 MariaDB
1 datetime + expr MONTHS Add months datetime + INTERVAL expr MONTH
2 datetime - expr DAYS Subtract days datetime - INTERVAL expr DAY
3 datetime + expr HOURS Add days datetime + INTERVAL expr HOUR
4 datetime - expr MINUTES Subtract minutes datetime - INTERVAL expr MINUTE
5 datetime + expr SECONDS Add seconds datetime + INTERVAL expr SECOND

For more information, see IBM DB2 to MariaDB Migration.