W3docs

How to separate DATE and TIME from DATETIME in MySQL?

You can use the DATE() and TIME() functions to extract the date and time parts of a DATETIME value in MySQL.

You can use the DATE() and TIME() functions to extract the date and time parts of a DATETIME value in MySQL. Here is an example:

Example of separating DATE and TIME from DATETIME in MySQL

SELECT DATE(datetime_column) AS date, TIME(datetime_column) AS time
FROM table_name;

This will return a result set with two columns: date, which contains the date part of the datetime_column, and time, which contains the time part. Note that DATE() and TIME() return native MySQL DATE and TIME data types rather than strings. If the datetime_column contains NULL, both functions will return NULL.

You can also use the DATE_FORMAT() function to format the date and time parts in a specific way. For example:

Example of using DATE_FORMAT() to format the date and time parts in a specific way in MySQL

SELECT DATE_FORMAT(datetime_column, '%Y-%m-%d') AS date, 
       DATE_FORMAT(datetime_column, '%H:%i:%s') AS time
FROM table_name;

This will return the date in the YYYY-MM-DD format and the time in the HH:MM:SS format, where %i represents minutes. You can find more information about the DATE_FORMAT() function and the available formatting options in the MySQL documentation.