date in mysql code example
Example 1: convert_tz mysql
CONVERT_TZ(datetime, from_tz, to_tz)
Example:
SELECT CONVERT_TZ('2031-09-21 02:42:14', 'UTC', 'America/New_York');
output: 2031-09-20 22:42:14
Example 2: mysql format date
DATE_FORMAT(date, format)
SELECT DATE_FORMAT(dateField, '%m/%d/%Y') FROM TableName;
Example 3: mysql current date
SELECT NOW();
It returns current date and time.
Example 4: mysql current time
CURRENT_TIME return HH:ii:ss format time in mysql
Example 5: date mysql
SELECT *
FROM table
WHERE date_to_find = '2020-05-25'
Example 6: get individual date elements in mysql
SELECT YEAR(NOW());
SELECT MONTH(NOW());
SELECT DAY(NOW());
SELECT HOUR(NOW());
SELECT MINUTE(NOW());
SELECT SECOND(NOW());