dimanche 3 avril 2016

Query date range using Android stored System.currentTimeMillis() values

I have been building my first app in Android Studio and have learned a lot thus far.

I have stored the current time in a column in my sqlite database using the System.currentTimeMillis() method that PearsonsArtPhoto recommended here: Best way to work with dates in Android SQLite

long datetime = System.currentTimeMillis(); values.put(CONSUMED_DATE, datetime);

The store value looks something like this: 1459578421261 which obviously looks nothing like a datetime value.

I am wanting to query the current time and date to search for values that are between todays date time which should be 12AM to todays date time ending at 11:59PM. (Basically today's entries only)

However, being new to Android I am not sure how to do this. Here is a snippet of my query.

db = this.getReadableDatabase();
int startDateQueryDate = ?;
int endDateQueryDate = ?;

String query = "SELECT SUM("+COLUMN_CONSUMED+") FROM "+TABLE_NAME_TEST+"where Date BETWEEN '" + startDateQueryDate + "' AND '" + endDateQueryDate + "';
Cursor cursor = db.rawQuery(query, null);

How do I retrieve todays entries by using the between query on System.currentTimeMillis() stored values?

Aucun commentaire:

Enregistrer un commentaire