MySQL Timestamp format
Asked Answered
N

3

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 ?

Nancinancie answered 16/11, 2013 at 15:37 Comment(0)
P
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');
Perished answered 16/11, 2013 at 15:39 Comment(0)
G
14
SELECT DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%s') 
Galven answered 16/11, 2013 at 15:41 Comment(0)
C
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')
Circumfuse answered 14/6, 2018 at 19:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.