Store a Javascript timestamp into a TIMESTAMP column

suggest change

If 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.)

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents