Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL: Convert INT to DATETIME

Tags:

datetime

mysql

I have a UNIX-type timestamp stored in an INT column in MySQL. What is the proper way to retrieve this as a MySQL DATETIME?

(I found the answer when re-scanning the MySQL Date functions, but didn't see the answer on SO. Figured it should be here.)

like image 317
pix0r Avatar asked Mar 02 '10 23:03

pix0r


People also ask

How can get date in dd mm yyyy format in MySQL?

The MySQL DATE_FORMAT() function formats a date value with a given specified format. You may also use MySQL DATE_FORMAT() on datetime values and use some of the formats specified for the TIME_FORMAT() function to format the time value as well. Let us take a look at the syntax of DATE_FORMAT() and some examples.

What is Date_add in MySQL?

The DATE_ADD() function adds a time/date interval to a date and then returns the date.

What is To_char in MySQL?

Description. The TO_CHAR function converts an expr of type date, datetime, time or timestamp to a string. The optional fmt argument supports YYYY/YYY/YY/RRRR/RR/MM/MON/MONTH/MI/DD/DY/HH/HH12/HH24/SS and special characters. The default value is "YYYY-MM-DD HH24:MI:SS".


2 Answers

FROM_UNIXTIME()

like image 192
Rob Avatar answered Sep 20 '22 16:09

Rob


select from_unixtime(column,'%Y-%m-%d') from myTable;  
like image 37
user2970312 Avatar answered Sep 18 '22 16:09

user2970312