In MySQL Date Or Time Function Part-1 we will discuss about the ADDDATE Function, ADDTIME Function, CONVERT_TZ Function, CURDATE Function, CURRENT_DATE Function, CURRENT_TIME Function, CURTIME Function, CURRENT_TIMESTAMP Function
ADDDATE Function:- ADDDATE Function is used for returning the Date or time after adding the interval of date or time. ADDDATE Function is similar or a synonym of the DATE_ADD Function.
Syntax:- ADDDATE(date, INTERVAL expr addunit)
OR
ADDDATE(date, days)
Example:-
SELECT ADDDATE(“2023-01-20 08:25:12”, INTERVAL 15 MINUTE);
Output:- 2023-01-20 08:40:12
SELECT ADDDATE(“2023-01-20 08:25:12”, INTERVAL -5 HOUR);
Output:- 2023-01-20 03:25:12
SELECT ADDDATE(“2023-01-20 08:25:12”, INTERVAL -7 MONTH);
Output:- 2022-06-20 08:25:12
SELECT ADDDATE(“2023-01-20 08:25:12”, INTERVAL 4 DAY);
Output:- 2023-01-24 08:25:12
ADDTIME Function:- ADDTIME Function is used for returning time or date time after the addition of an interval of time or date time.
Syntax:- ADDTIME(date time, add time interval )
Example:-
SELECT ADDTIME(“07:25:15.000005”, “1:15:10.000002”);
Output:- 08:40:25.000007
SELECT ADDTIME(“2023-01-10 07:25:15.000005”, “3 1:15:10.000002”);
Output:- 2023-01-13 08:40:25.000007
SELECT ADDTIME(“2023-01-10 07:25:15”, “5”);
Output:- 2023-01-10 07:25:20
CONVERT_TZ Function:- CONVERT_TZ Function is used for returning Date Time after converting one time zone to another time zone.
Syntax:- CONVERT_TZ (date time, from time zone, to time zone)
Example:-
SELECT CONVERT_TZ(‘2023-1-16 17:49:10’, ‘+00:00’, ‘+05:30’);
Output:- 2023-01-16 23:19:10 //GMT to IST
CURDATE Function:- CURDATE Function is used for returning the current date. CURDATE Function and CURRENT_DATE Function are equal or synonyms.
Syntax:- CURDATE()
Example:-
SELECT CURDATE();
Output:- 2023-02-02
SELECT CURDATE() + 5;
Output:- 20230207
CURRENT_DATE Function :- CURRENT_DATE Function and CURDATE Function are equal or synonyms.
Syntax:- CURRENT_DATE()
CURRENT_TIME Function:- CURRENT_TIME Function is used for returning the current time. CURRENT_TIME Function and CURTIME Function are equal or synonyms.
Syntax:- CURRENT_TIME()
Example:-
SELECT CURRENT_TIME();
Output:- 23:09:03
SELECT CURRENT_TIME()+5;
Output:- 230955
CURTIME Function:- CURTIME Function and CURRENT_TIME Function are equal or synonyms.
Syntax:- CURTIME()
CURRENT_TIMESTAMP Function:- CURRENT_TIMESTAMP Function is used for returning the current date and time.
Syntax:- CURRENT_TIMESTAMP()
Example:-
SELECT CURRENT_TIMESTAMP();
Output:- 2023-02-02 23:15:05
SELECT CURRENT_TIMESTAMP() + 5;
Output:- 20230202231612
Read Also:-
MySQL Date Or Time Function Part-2
MySQL Date Or Time Function Part-3
MySQL Date Or Time Function Part-4
MySQL Date Or Time Function Part-5
MySQL Date Or Time Function Part-6
MySQL Date Or Time Function Part-7
MySQL Date Or Time Function Part-8
Read more detail about MySQL Date Or Time Function manual