datetime mysql code example

Example 1: php mysql datetime

date("Y-m-d H:i:s")

Example 2: mysql get time from datetime

SELECT 
date_format(datecol, '%H:%i:%s') as 'time' FROM table;
-- eg. 10:33:10

Example 3: date vs datetime

DATE : YYYY-MM-DD format
DATETIME : YYYY-MM-DD HH:MM:SS format
TIMESTAMP : X s from 1970 format
TIME : HH:MM:SS format

Example 4: mysql timestamp format

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

Example 5: date mysql

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