0

I have a Java application where I get a timestamp with the call System.currentTimeInMills();

This returns values like 1331255526000.

Now I want to store these values in a MySQL database in a Datetime(6) field and I've written the following query:

$sql = 'INSERT INTO attention '. '(ParticipantID,SessionId, Timestamp, Attention) '. 'VALUES (' .$participant. ',' .$session. ',FROM_UNIXTIME(' .$timestamp. '),' .$attention. ')';

Where the variable $timestamp is the value I retrieve in Java.

However, this query is not working. What am I doing wrong?

Guns
  • 2,678
  • 2
  • 23
  • 51
Fischer Ludrian
  • 629
  • 1
  • 9
  • 23

1 Answers1

1

use in mysql: from_unixtime($yourvariable / 1000)

Mysql timestamps are not in ms , but in seconds.

nl-x
  • 11,762
  • 7
  • 33
  • 61
  • Yes, but I want milliseconds precision. – Fischer Ludrian May 12 '14 at 09:59
  • Have you tried it? It should give you the fractions. Only when working with temp values, before MySQL version 5.6.4, the fractions would go lost. See http://dev.mysql.com/doc/refman/5.6/en/fractional-seconds.html – nl-x May 12 '14 at 10:02