mysql datetime code example

Example 1: php mysql datetime

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

Example 2: mysql current date

SELECT NOW();
It returns current date and time.

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: how to assign date field for table in mysql

CREATE TABLE people (
    id INT AUTO_INCREMENT PRIMARY KEY,
    first_name VARCHAR(50) NOT NULL,
    last_name VARCHAR(50) NOT NULL,
    birth_date DATE NOT NULL
);

Example 5: date mysql

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

Tags:

Php Example