mysql date part code example
Example 1: date_part mysql
mysql> SELECT EXTRACT(YEAR FROM '2019-07-02');
-> 2019
mysql> SELECT EXTRACT(YEAR_MONTH FROM '2019-07-02 01:02:03');
-> 201907
mysql> SELECT EXTRACT(DAY_MINUTE FROM '2019-07-02 01:02:03');
-> 20102
mysql> SELECT EXTRACT(MICROSECOND
-> FROM '2003-01-02 10:30:00.000123');
-> 123
Example 2: mysql current date
SELECT NOW();
It returns current date and time.
Example 3: mysql current time
CURRENT_TIME return HH:ii:ss format time in mysql
Example 4: mysql get date from datetime
WHERE DATE(datetime) = '2009-10-20'
Example 5: get individual date elements in mysql
SELECT YEAR(NOW());
SELECT MONTH(NOW());
SELECT DAY(NOW());
SELECT HOUR(NOW());
SELECT MINUTE(NOW());
SELECT SECOND(NOW());