DATEADD to TIMESTAMPADD - Sybase ASE to MariaDB Migration

In Sybase ASE you can use DATEADD function to add an interval to the datetime value. In MariaDB you can use TIMESTAMPADD function, but note that the interval unit specifiers can be different:

Sybase ASE:

  -- Add 1 day to the current datetime
  SELECT DATEADD(dd, 1, GETDATE())
  # 2017-12-17 10:38:11.343
 
  -- Subtract 1 day from the current datetime
  SELECT DATEADD(dd, -1, GETDATE())
  # 2017-12-15 10:38:11.343

MariaDB:

  -- Add 1 day to the current datetime
  SELECT TIMESTAMPADD(day, 1, NOW(3));
  # 2017-12-17 10:38:11.343
 
  -- Subtract 1 day from the current datetime
  SELECT TIMESTAMPADD(day, -1, NOW(3));
  # 2017-12-15 10:38:11.343

Mapping Sybase ASE DATEADD Interval Units to MariaDB

You can use SQLines SQL Converter to convert Sybase ASE DATEADD function to TIMESTAMPADD that maps the interval units to the appropriate values in MariaDB:

Sybase ASE MariaDB
yy year Interval in years year
qq quarter Interval in quarters quarter
mm month Interval in months month
wk week Interval in weeks week
dd day Interval in days day
dy dayofyear Interval in days day
dw weekday Interval in days day
hh hour Interval in hours hour
mi minute Interval in minutes minute
ss second Interval in seconds second
ms millisecond Interval in milliseconds *1000 microsecond
us microsecond Interval in microseconds microsecond

Conversion examples:

Sybase ASE MariaDB
1 SELECT DATEADD(mi, 3, GETDATE()) SELECT TIMESTAMPADD(minute, 3, NOW());
2 SELECT DATEADD(hh, 3, GETDATE()) SELECT TIMESTAMPADD(hour, 3, NOW());
3 SELECT DATEADD(mm, 1, GETDATE()) SELECT TIMESTAMPADD(month, 3, NOW());

For more information, see: