I want to save data in Firebase according to Firebase local server time and date as opposed to the local system date, which can be wrong if a user's mobile phone date is wrong. Then I want to retrieve it by applying date query like SQL query (giving me the data between the two dates and add specific colmn). How can I do that in Android using Java?
-
Please read https://stackoverflow.com/help/how-to-ask – David Baak Oct 11 '18 at 10:40
2 Answers
Depending on what platform/language you write - use e.g. https://firebase.google.com/docs/reference/android/com/google/firebase/firestore/ServerTimestamp

- 422
- 3
- 8
-
The documentation that you've shared is for Cloud Firestore and OP is asking for Firebase realtime database which a different product. – Alex Mamo Oct 11 '18 at 14:10
I want to save data in Firebase according to Firebase local server time and date
You can achieve this, using my answer from this post. As you can see, I have used ServerValue.TIMESTAMP:
A placeholder value for auto-populating the current timestamp (time since the Unix epoch, in milliseconds) by the Firebase Database servers.
So this timestamp isn't related in any way with the mobile phone date.
Then I want to retrieve it by applying date query like SQL query (giving me the difference between the two dates).
You can achieve this using the following two methods. The firts one would be startAt()
:
Return items greater than or equal to the specified key or value depending on the order-by method chosen.
And the second one would be endAt()
:
Return items less than or equal to the specified key or value depending on the order-by method chosen.

- 130,605
- 17
- 163
- 193
-
i update the question. i am able to save data with timestamp but how can i get back according to timestamp – Akmal Masud Oct 11 '18 at 15:25
-
Have you tried to use use `startAt()` and `endAt()` methods, as my above solution? – Alex Mamo Oct 11 '18 at 15:28
-
https://stackoverflow.com/questions/52765817/retrieve-data-from-firebase-between-timestamps I attached a pic of my realtimedatabase which can help you understand my question – Akmal Masud Oct 11 '18 at 17:26