Query the firebase database using server value timestamp

1,802 views
Skip to first unread message

Kadir Zaini Rusbi

unread,
Oct 7, 2016, 2:00:27 AM10/7/16
to Firebase Google Group
Hello, I have trouble in solving the following:

Currently Im using ServerValue.TIMESTAMP to store date inside Firebase Database, and I can easily retreving it as date via: new Date((long) dataSnapshot.getValue());

The problem is, when i wanted query by using 2 dates:

Query q = databaseReference.orderByChild("datePosted").startAt(x).endAt(y);
where y is current date/time, x is one month before y,

I can't assigned ServerValue.TIMESTAMP as y, since method don't accept Map.
I can't figure out how to modify ServerValue.TIMESTAMP in order to assign it to x.
I'm not really sure whats the data format for ServerValue.TIMESTAMP inside Firebase Database, they shows as long format though.

Can anyone suggest the possible way to query between 2 ServerValue.TIMESTAMPs?
Side note, I'm working on Android Studio.

Kato Richardson

unread,
Oct 7, 2016, 2:55:30 PM10/7/16
to Firebase Google Group
Hello Kadir,

You can monitor `/.info/serverTimeOffset` as described here to create an approximation of TIMESTAMP, but there aren't a lot of cases where a few milliseconds of skew on reads is going to be a problem, so probably `new Date()` is just fine for most apps, so this may be unnecessary optimization.

☼, Kato

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/5159534b-f5f5-4c64-9c7a-9f914439fe35%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

Reply all
Reply to author
Forward
0 new messages