Aug 27, 2024
SELECT CURRENT_DATE;
SELECT CURRENT_TIME;
SELECT CURRENT_TIMESTAMP;
SELECT DATE(current_timestamp);
SELECT TIME(current_timestamp);
SELECT YEAR(date_time_expression);
SELECT MONTH(date_time_expression);
SELECT DAY(date_time_expression);
EXTRACT(component FROM date_time_expression);
SELECT ID, NAME, EXTRACT(DAY FROM date_of_birth) FROM employee;
DATEDIFF(date1, date2);
TIMEDIFF(time1, time2);
DATE_ADD(date_time_expression, INTERVAL value unit);
DATE_SUB(date_time_expression, INTERVAL value unit);
DATE_FORMAT(date_time_expression, 'format_string');
%d %b %Y
(Day, Month name, Year).Adding One Month:
SELECT ID, NAME, DATE_ADD(date_of_birth, INTERVAL 1 MONTH) AS updated_date_of_birth FROM employee;
Subtracting Three Years:
SELECT ID, NAME, DATE_SUB(date_of_birth, INTERVAL 3 YEAR) AS updated_date_of_birth FROM employee;
Formatting Date:
SELECT ID, NAME, DATE_FORMAT(date_of_birth, '%d %b %Y') AS new_date_of_birth FROM employee;