If you access this from an API-based client (I assume this is because of the โ? In the queryโ), you can do this from within your program, not through SQL.
Note. The rest is for JDBC syntax, other APIs / languages โโwill be different from the syntax, but should be conceptually the same.
On the side of the insert do
PreparedStatement stmt = connection.prepareStatement( "INSERT INTO messages " + "(typeId, messageTime, stationId, message) VALUES " + "(?, ?, ?, ?)" ); stmt.setInt(1, typeId); stmt.setDate(2, new java.sql.Date(System.currentTimeMillis())); stmt.setInt(3, stationId); stmt.setString(4, message);
On the request side, do:
PrepatedStatement stmt = connection.prepareStatement( "SELECT typeId, messageTime, stationId, message " + "from messages where messageTime < ?"); long yesterday = System.currentTimeMillis() - 86400000;
This should work in a portable way.
source share