문제

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?

도움이 되었습니까?

해결책

use in mysql: from_unixtime($yourvariable / 1000)

Mysql timestamps are not in ms , but in seconds.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top