Q:

How to query last 7 days' data from Firestore Android

I want to query Cloud Firestore data in last 7 days. I am using server timestamp of Firestore also storing the time in millis.
CollectionReference IOTransactions = db.collection(userID)
                .document("userData").collection("StockTransactions");

        Query transactionsQuery = IOTransactions.orderBy("timestamp",Query.Direction.DESCENDING);

        transactionsQuery.addSnapshotListener(new EventListener<QuerySnapshot>() {
            @Override
            public void onEvent(@javax.annotation.Nullable QuerySnapshot queryDocumentSnapshots, @javax.annotation.Nullable FirebaseFirestoreException e) {
                if (e != null) {
                    Log.w("FirestoreDemo", "Listen failed.", e);
                    return;
                }
                for (QueryDocumentSnapshot doc : queryDocumentSnapshots) {
                    if (doc.get("timestamp") != null)
                        transactionsList.add(doc.toObject(StockTransaction.class));
                    Log.d("Firestore", "Added item");
                }

                if(transactionsList.size() < 1 )
                    emptyTransactionsPage.setVisibility(View.VISIBLE);

                Log.d("Firestore Reading", "Successfully fetched");
                adapter.notifyDataSetChanged();
                pb.setVisibility(View.INVISIBLE);

            }
        });

How can I query the data created in last 7 days?

A:

I am using server timestamp of Firestore also storing the time in milliseconds.

So if you are storing the timestamp in milliseconds, you are doing it wrong.

How can I query the data created in last 7 days.

To be able to query your database according to a periode of time, your timestamp property should be o type Date and not long. To see how you can achieve this, please take a look at my answer from this post.
Once you have the property set correctly, a query that looks like this should do the trick:
IOTransactions.whereLessThan("timestamp", now).whereGreaterThan("timestamp", sevenDayAgo);

In which now and sevenDayAgo are two Date objects representing the present time and a moment in time seven days ago.

