Home > other >  Convert dd mmm yyyy to datetime in Mysql
Convert dd mmm yyyy to datetime in Mysql

Time:06-03

In our database, we have date value as "12 JAN 2021" and we need to convert it as 2021-01-12 12:05:11. Can someone help me with this please?

CodePudding user response:

In case the value in the database is a datetime you can just format it using
FORMAT(YourDate,'yyyy-MM-dd HH:mm:ss')
or if it is possible change the datetime format on the machine running your SQL instance.

Worst case scenario you would need to split the value using substring and combine it into a string that matches the format you are looking for.

CodePudding user response:

Insert date to mysql database.
$added_on = date('Y-m-d H:i:s'); //2020-10-22 13:52:26

  • Related