質問

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.

役に立ちましたか?

解決

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)+"'

"

他のヒント

Compare the current hour with the hour on the timestamp's record.

If you are using sql server:

SELECT DATEPART(hh, GETDATE()) --current hour

SELECT DATEOART(hh, ColumnStoredInDB) --stored hour

Spoiler: Simply take the ColumnStoredInDB from the current hour and if the difference is < 1 that user has been in the system for the last hour. If the difference >=1 you can skip that record

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top