How to part DATE and TIME from DATETIME in MySQL How to part DATE and TIME from DATETIME in MySQL sql sql

How to part DATE and TIME from DATETIME in MySQL


You can achieve that using DATE_FORMAT() (click the link for more other formats)

SELECT DATE_FORMAT(colName, '%Y-%m-%d') DATEONLY,        DATE_FORMAT(colName,'%H:%i:%s') TIMEONLY

SQLFiddle Demo


per the mysql documentation, the DATE() function will pull the date part of a datetime feild, and TIME() for the time portion. so I would try:

select DATE(dateTimeField) as Date, TIME(dateTimeField) as Time, col2, col3, FROM Table1 ...


Try:

SELECT DATE(`date_time_field`) AS date_part, TIME(`date_time_field`) AS time_part FROM `your_table`