Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL - Convert Datetime format

I try to change my format Datetime on MySQL

T got a table historic with some columns and some all them have this format DATETIME :

JJ/MM/AAAA HH:MM

I need to change to :

AAAA-MM-JJ HH:MM:SS

I don't have the variable for SS I would like to take 00.

Example

01/12/2012 12:23 > 2012-12-01 12:23:00

Thanks

like image 234
user1324059 Avatar asked Apr 18 '12 08:04

user1324059


1 Answers

You need to use Format Function for that

For above you can use

SELECT DATE_FORMAT([YOURCOLUMNNAME],'%Y-%m-%d %h:%i:%s') from [YOURTABLENAME];

For all the conversion you can refer to.

http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format

like image 138
Malhar Chudasama Avatar answered Sep 20 '22 21:09

Malhar Chudasama