ADDDATE() and ADDTIME() Function in MariaDB
Last Updated :
19 Oct, 2020
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'
Similar Reads
DATE() and DATE_ADD() Function in MariaDB 1. DATE() Function : In MariaDB, the DATE() function is used to return extracts the date value from a date or datetime expression. In this function, the first parameter will be a date or DateTime. This function will return extracts the date value from the expression. If the expression is not date or
2 min read
DATE_FORMAT() Function in MariaDB DATE_FORMAT() Function : In MariaDB, the DATE_FORMAT() function uses two parameters - a date as specified by a format mask. In this function, the first parameter will be a date and the second parameter will be the mask. This function will return the date in the given mask. This function will convert
3 min read
EXTRACT() and DAYOFYEAR() Function in MariaDB 1. EXTRACT() Function : In MariaDB, the EXTRACT() function is used to return extracts the extracts parts from a date. In this function, the first parameter will be an expression. The first part of expression will be unit and second part of expression will be a date. This function will return extract
2 min read
HOUR() and FROM_DAYS() function in MariaDB 1. HOUR() Function : In MariaDB, the HOUR() function is used to return the hour portion of a date value. In this function, the first parameter will be date_value. This function will return HOUR part of the given date. Since a time value can be range from -838:59:59' to '838:59:59' so that this funct
2 min read
TO_DAYS Function and WEEK Function in MariaDB TO_DAYS Function : In MariaDB, TO_DAYS Function converts a date into numeric days. In this function, the first parameter will be the Date. This function returns the numeric days of the date. This function is to be used only with dates within the Gregorian calendar. This function will return NULL if
2 min read