javasqlclienttimestampdatabase-server

SQL timestamp on Update read in Java


I am writing a Client Server Application now when the Client sends a command to the Server the Record in the SQL Database is updated and On Update a Timestamp is set on a field. But now I want to read all the Users in the SQL Database that where online in the last hour with the Timestamp.

So this is how far I am:

SELECT username FROM users WHERE lastonline...

lastonline is the field with the timestamp of the users last update. I now have no Idea how to check if he was online in the last hour.

I thank you for you help.


Solution

  • Select username FROM user WHERE lastoinline>"date now - 1 hour" AND lastoinline<="date now"

    Date dеNow = new Date();
    Date веBefore = tdNow; tdBefore.setHours(tdBefore.getHours()-1);
    String query = "SELECT username FROM user WHERE lastonline>='"+(dtBefore.getTime/1000)+"' AND lastonline<='"+(dtNow.getTime/1000)+"'
    

    "