Convert unix timestamp to datetime with milliseconds in MySQL

2020-03-13T05:54:15

Problem

Converting unix timestamp to datetime while retaining milliseconds.

Background

I am receiving unix timestamp in the following format:

  • 1584049707

Then I am trying to send it by means of PHP to a column in MySQL that is datetime(3) using TO_TIMESTAMP(). I have also tried FROM_UNIXTIME(), but with the same results.

SQL

$sql = "
  INSERT INTO assoc_table (timestart, timeend) 
  VALUES (TO_TIMESTAMP(:timestart), TO_TIMESTAMP(:timeend))
";

Result

  • 2020-03-12 22:42:23.000

For some reason it does not register the milliseconds.

Desired outcome

  • To get the milliseconds out of the unix timestamp and into the datetime column.

Copyright License:
Author:「kexxcream」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/60662325/convert-unix-timestamp-to-datetime-with-milliseconds-in-mysql

About “Convert unix timestamp to datetime with milliseconds in MySQL” questions

Problem Converting unix timestamp to datetime while retaining milliseconds. Background I am receiving unix timestamp in the following format: 1584049707 Then I am trying to send it by means of...
I have a list of unix timestamps that all contain milliseconds -- they are 13 digits long. When I run the timestamp through datetime.fromtimestamp(unix_timestamp) it returns a ValueError: Year Out of
These both correctly return the current UNIX timestamp: SELECT UNIX_TIMESTAMP(LOCALTIMESTAMP()); #MySql echo time(); //PHP But I'm storing UTC_TIMESTAMPs in my database (not LOCALTIMESTAMPs). Ho...
I'm confused about timezone differences when converting a MySQL datetime to Unix timestamp. It appears to me that MySQL datetimes (2011-02-07 09:45:00) are in the server's local timezone. I want to
I have a TIMESTAMP column in a MySQL table which I am accessing through JDBC. On the Java side, I am using JodaTime. I would like to represent all my instants as milliseconds since the Unix epoch...
I have a table with a date column that is formatted as a DATETIME(3). I would like to convert it to a BIGINT(13) that stores that datetime as the milliseconds from unix epoch. How can I modify the
I have the following string 2013-04-12 16:00:15.041 What is the C++ way to convert this string into a 64bit UNIX timestamp? Most question on here deal with only having the timestamp until seconds...
How can I use PHP to get a UNIX timestamp like what I get from the JS method .getTime()? I seem to be having trouble since .getTime() returns milliseconds. I know I have to convert the timestamps f...
I'm trying to do something really simple, convert a datetime object three days into the future into a Unix UTC timestamp: import datetime, time then = datetime.datetime.now() + datetime.timedelta(...
How do I convert timestamps in a MySQL View? I have a MySQL View for data exchange between 2 different software tools. The original table is a unix timestamp as int(11). The other software expec...

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.