25

I have exported my database to a CSV file and the timestamp now liiks like this:

1384204028

How can I convert it to the typical format, for example 2013-01-19 03:14:07 ?

3 Answers 3

36

Use FROM_UNIXTIME()

SELECT FROM_UNIXTIME(1384204028);

or (equivalent but with parameter to control the format):

SELECT FROM_UNIXTIME(1384204028, '%Y-%m-%d %H:%i:%s');
Sign up to request clarification or add additional context in comments.

Comments

14
SELECT DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%s') 

Comments

0

if you just want to add a line in your DB-table, where you have a field as TIMESTAMP, you don't need to call a function. You just can pas a string, sql will do the rest.

INSERT INTO `DB_TABLE`(`id`, `message`, `next_time`) VALUES (12, 'hallo world', '20180601151343')

and will even work like this:

INSERT INTO `DB_TABLE`(`id`, `message`, `next_time`) VALUES (12, 'hallo world', '2018-06-01 15:13:43')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.