Store a Javascript timestamp into a TIMESTAMP column
suggest changeIf you have a Javascript timestamp value, for example 1478960868932, you can convert that to a MySQL fractional time value like this:
FROM_UNIXTIME(1478960868932 * 0.001)
It’s simple to use that kind of expression to store your Javascript timestamp into a MySQL table. table is reserved, so quote it. A TIMESTAMP or DATETIME column without a fractional scale stores whole seconds and drops the milliseconds. Use TIMESTAMP(3) or DATETIME(3) to keep them.
INSERT INTO `table` (col) VALUES (FROM_UNIXTIME(1478960868932 * 0.001));
(Obviously, you’ll want to insert other columns.)
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents