0

I am making a social media app in which user posts data on firebase, now I want to retrieve all the data from firebase that was posted on current date, below is my firebase database structure

enter image description here

I'm posting the timerstamp too, but I don't know how to retrieve the data according to the current date.

This is my code segment for getting timerstamp value but I'm unable to get the value:

mDatabase= FirebaseDatabase.getInstance().getReference().child("Profiles");
    mQuery=mDatabase.orderByChild("timerstamp").startAt(ServerValue.TIMESTAMP);

but ServerValue.TIMESTAMP is red underlined, and when I typecast it to string the query is getting null.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Syyam Noor
  • 67
  • 10
  • `ServerValue.TIMESTAMP` is a placeholder/marker that is replaced by the actual timestamp on **write** operations. You cannot use it to filter in queries, since those are a *read* operation. – Frank van Puffelen Aug 17 '17 at 20:43
  • so what should i do if i want to retrieve all the data posted on current date? – Syyam Noor Aug 17 '17 at 20:46
  • If you want to get the items after *now*, passing the current timestamp into `startAt` is a good approximation. See https://stackoverflow.com/questions/33885059/how-to-only-get-new-data-without-existing-data-from-a-firebase/33885787#33885787 for a JavaScript example or use `System.currentTimeMillis()`. – Frank van Puffelen Aug 17 '17 at 20:48
  • does start at takes value as integer or string? for comparing? – Syyam Noor Aug 17 '17 at 20:55
  • It takes a value of the type you're comparing against. So in your case that would be a number. – Frank van Puffelen Aug 17 '17 at 20:58
  • i'm using this now: `tsLong = System.currentTimeMillis()/1000; mDatabase= FirebaseDatabase.getInstance().getReference().child("Profiles"); mQuery=mDatabase.orderByChild("timerstamp").startAt(tsLong);` but still no success – Syyam Noor Aug 17 '17 at 21:14
  • ok so what should i do if i want the timestamp of current date excluding the time? – Syyam Noor Aug 17 '17 at 21:27
  • Create a range query starting at the day at `0:00` and ending at `23:59:59`. https://www.google.com/search?q=java+timestamp+of+current+date+excluding+the+time – Frank van Puffelen Aug 17 '17 at 22:35

0 Answers0