Convert date format in MySQL

0
88
MySQL

Here is the example to convert date format in MySQL

Suppose you have column name as date_created which is storing datetime in format like m/d/Y H:i and you want to convert in timestamp format like Y-m-d H:i:s.

select STR_TO_DATE(date_created, ‘%m/%d/%Y %H:%i’) as new_date from table_name

This query will select the date in new format.

Here you will find one more example. suppose you have two columns separated with date and time now you want to concat them and want to show in timestamp format.

select STR_TO_DATE(concat(date, ‘ ‘, time), ‘%m/%d/%Y %H:%i’) as new_date from table_name

LEAVE A REPLY

Please enter your comment!
Please enter your name here