1

I am trying to create a new column in my table to convert a unix time column into human readable date and time.

I have found a few functions but am having trouble with the syntax as I do not normally use mysql. In this case it is required though.

Also, the unix time column I currently have is in milliseconds, could you please assist with this also.

Thanks

1 Answer 1

1

Is the unix time column in the same table ? You can add a datetime column to the table, then run an update to translate the old records:

update foo_table set datetimecolumn=from_unixtime(unixcolumn);

Then you can add a trigger to the table to auto translate every time an insert is performed:

CREATE TRIGGER `toDateTime` BEFORE INSERT ON `foo_table` FOR EACH ROW  set new.datetimecolumn=from_unixtime(new.unixcolumn);

UPDATE:

as it is in milliseconds, you can use this

from_unixtime(CAST(unixcolumn/1000 as BIGINT))
Sign up to request clarification or add additional context in comments.

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.