0

I need to get all documents within the specified date/time range (all within the same day from 00:00:00 to 23:59:59)

Ive tried multiple querys, and there is nothing in the docs about querying the same date with different times. Most examples show a specific date/time, but I need the query to be all documents scheduled for today(dynamic)

private void loadList() {
    Calendar c = Calendar.getInstance();
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    Date todayStart = c.getTime();
    c.set(Calendar.HOUR_OF_DAY, 23);
    c.set(Calendar.MINUTE, 59);
    c.set(Calendar.SECOND, 59);
    Date todayEnd = c.getTime();
    Log.d(TAG, "this is the date/time for todayStart" + todayStart);
    Log.d(TAG, "this is the date/time for todayEnd" + todayEnd);

    mFirestoreDB.collection("events")
            .whereGreaterThanOrEqualTo("dateScheduled", todayStart)
            .whereLessThanOrEqualTo("dateScheduled", todayEnd)
            .get()
            .addOnCompleteListener(task -> {
                if (task.isSuccessful()) {... ect

Example Firestore field: dateScheduled May 5, 2019 at 12:00:00 AM UTC-4

Example 2:

enter image description here

The Log.d is showing correct date/times for today, and I have many documents that have the todays date scheduled. This should return all documents with any time frame for todays date. Any help is appreciated!

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Please show an example of a document that you expect to match. Please be specific about its contents - fields and data types. Without seeing exactly what you expect to match, it's not possible for us to predict if it's going to match. – Doug Stevenson May 06 '19 at 00:09
  • I thought the example under the code snippet was what you would like to see, but I added a picture. – Thomas Waldorf May 06 '19 at 00:17
  • It wasn't 100% clear if you are working with a Timestamp type field, or just a formatted string. – Doug Stevenson May 06 '19 at 00:25
  • check out this. Map updates = new HashMap<>(); updates.put("latestUpdateTimestamp", FieldValue.serverTimestamp()); - https://stackoverflow.com/questions/47355540/firestore-adding-server-timestamp-field-to-the-object-which-being-added – Elias Fazel May 06 '19 at 01:02

0 Answers0