Reputation: 25
I want to retrieve data from FIREBASE between two Timestamps and I also attached my realtimedatabase Pic. I want to make a graph between date and price .I am making an app which shows owner of store how's its sales going according to time(day,month or year) and Also show total price by adding price child . how can i do that?
Upvotes: 0
Views: 1644
Reputation: 138969
To solve this, please use the following code:
String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
Query query = rootRef.child("User").child(uid).child("M3").orderByChild("timestamp").startAt(startTime).endAt(endTime);
ValueEventListener valueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot ds : dataSnapshot.getChildren()) {
long price = ds.child("price").getValue(Long.class);
Log.d(TAG, "price: " + long);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Log.d(TAG, databaseError.getMessage());
}
};
query.addListenerForSingleValueEvent(valueEventListener);
In which startTime
is the timestamp from which you want to start query and endTime
is the timestamp where you end the query.
Upvotes: 1