Get Current Date-Time Elsewhere
If you cannot trust the current date-time on the user’s device/computer, then you have two alternatives:
- Get the current date-time from somewhere else.
- See this Question or this Question for getting current date-time from time servers using Java/Android.
- See this Question for getting current date-time from your database server.
- Let your database server use its own date-time when searching for records.
See Questions like this or this. Pay careful attention to the various date-time functions offered by your particular database. For example, some commands return the moment when the transactions began while others return the current moment of execution. A few commands are standard SQL while most are proprietary. As an example, see the Postgres date-time functions doc.
Joda-Time
If you get the time from elsewhere, then you need to work with the date-time values in Java. When doing such work, use a good date-time library. For Android that means the Joda-Time library. Avoid the bundled java.util.Date/.Calendar as they are notoriously troublesome.
There are many other Questions and Answers on StackOverflow on this topic, but here's a quick untested example. I assume you are using a JDBC driver to obtain a java.sql.Timestamp value from your database.
java.sql.Timestamp ts = myResultSet.getTimestamp( "my_column_" ); // Get date-time object from your database via JDBC driver.
…
DateTime now = … // Get current date-time from other computer as discussed above.
DateTime when = new DateTime( ts , DateTimeZone.UTC ); // Convert java.sql.Timestamp to org.joda.time.DateTime object.
Boolean rowIsPast = when.isBefore( now ); // Compare DateTime objects.
If you are getting string representations of your data’s date-time values from the database, try to instead get an object via JDBC, a java.sql.Timestamp (or in the future, an object of a type defined by the new java.time package in Java 8 and later). If you must work with string representations, search for many examples on StackOverflow.com of parsing strings into date-time values in Java & Joda-Time (use the search term "joda").