date and time mysql code example

Example 1: get individual date elements in mysql

-- To get the year of a date in mysql
SELECT YEAR(NOW());

-- To get the month of a date in mysql
SELECT MONTH(NOW());

-- To get the day of a date in mysql
SELECT DAY(NOW());

-- To get the hour of a date in mysql
SELECT HOUR(NOW());

-- To get the minute of a date in mysql
SELECT MINUTE(NOW());

-- To get the second of a date in mysql
SELECT SECOND(NOW());

Example 2: mysql timestamp format

INSERT INTO ... VALUES ('YYYY-MM-DD HH:MM:SS');

Example 3: date mysql

-- sintax of date type in mysql:
-- ' YYYY-MM-DD ' 
SELECT *
FROM table
WHERE date_to_find = '2020-05-25'

Tags:

Php Example