datetime - Timestamp with a millisecond precision: How to save them in MySQL -


I have to develop an application using MySQL and I have to save values ​​like "1412792828893" which represent a timestamp But this is the exact millisecond, after 1.1.1970, declare the quantity of milliseconds as the line timestamp but unfortunately it does not work. All values ​​are set to 0000-00-00 00:00:00

  if not, then 'probability' (`id` int (11) Not zero is AUTO_INCREMENT, `Segment_id` et (11) not a null;` probability 'is not float,' measured_a 'timestamp nose, `provider_id' ent (11) null, primary key (` id`));   

How should the announcement be made to be able to save timestamp values ​​with this precision?

You declare columns with partial-time datatype in MySQL version 5.6.4 or later is required. Not sure if you have the right version? Try SELECT NOW (3) . If you get an error, you do not have the correct version. For example, DATETIME (3) will give you millisecond resolution in your timestamp, and TIMESTAMP (6) will give you a Microsoft resolution * on the niks-style timestamp.

Read it:

Now (3) will give you the current time with the millisecond precision from the operating system of your MySQL server.

If you have several milliseconds, try to get it DATETIME (3) value

  FROM_UNIXTIME (ms * 0.001)   

, for example, is shown in milliseconds.

(Note that MySQL internal partial arithmetic, such as * 0.001 , is always handled as a IEEE754 double precision floating point, therefore it is unlikely that you can see that the sun is white The dwarf star will lose accuracy before becoming a star.)

If you are using an earlier version of MySQL and you need the accuracy of the sub-time, your best way is to upgrade.

If for some reason you can not upgrade, you might consider using the BIGINT or DOUBLE column. To store JavaScript timestamps such as those numbers are FROM_UNIXTIME (col * 0.001) still work fine if you need the current time to store in such a column You can use UNIX_TIMESTAMP () * 1000

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -