Open In App

ADDDATE() and ADDTIME() Function in MariaDB

Improve
Improve
Like Article
Like
Save
Share
Report

1. ADDDATE Function :
In this function when a time/date interval added then ADDDATE function returns a date that is the actual functionalities of ADDDATE function. In this function, the first parameter will be a date and the second parameter will be the INTERVAL value unit. This function will return the Date with the adding given interval. This function works similarly to the DATE_ADD function. If the given interval is negative then it works like SUBDATE function.

Syntax :

ADDDATE( date, INTERVAL value unit )

You can also use this syntax also. Both are the same.

ADDDATE( date, days )

Parameter :

Parameters Description
Date Date to which the interval should be added.
Days Number of days to add to date 
value  The time/date interval that you wish to add.
unit The unit type of the interval such as DAY, MONTH, MINUTE, HOUR

Example-1 :

SELECT ADDDATE('2018-05-28', INTERVAL -3 MONTH);

Output :

'2018-02-28'

Example-2 :

SELECT ADDDATE('2016-06-07', 10);

Output :

'2016-06-17'

Example-3 :

SELECT ADDDATE
('2020-10-15 08:44:21.000001', 
INTERVAL '3:12.000001' 
MINUTE_MICROSECOND)

Output :

'2020-10-15 08:47:33.000002'

2. ADDTIME Function :
In MariaDB, The ADDTIME Function is used to return the time/DateTime value after which a certain time/date interval has been added. In this function, the first parameter will be a start_value and the second parameter will be the time. This function will return time/DateTime with the adding given interval. This function works similarly to the SUB TIME function. If the given interval is negative.

Syntax :

ADDTIME( start_value, time )

Parameters :

Parameters Description
start_value It is a time/DateTime value to which the time interval should be added.
time The value of the time interval which will be added in start_value.

Example-1 :

SELECT ADDTIME('07:25:23.999998', '5.000001');

Output :

'07:25:28.999999'

Example-2 :

SELECT ADDTIME('02:15:23.000001', '-8:12:15.003441');

Output :

'-05:56:52.003440'

Example-3 :

SELECT ADDTIME
('2020-05-17 08:44:21.000001', 
'5 4:3:2.000001');

Output :

'2020-05-22 12:47:23.000002'

Last Updated : 19 Oct, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads