Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+11 votes

Does anyone know how to timestamp a string in firebase using React so it could be sorted a certain way?

asked in CSC490_Spring202021 by (-499 points)

2 Answers

+1 vote

If you specifically want to use a timestamp, then you could try getting the time from a Date object, then use that as the key when storing your value. When you write to Firebase it automatically sorts the items in a branch by their key.

Also, if you have children in Firebase that themselves have multiple children, you can use OrderByChild() to order what you read by a specific child. The link below is to some documentation that has the orderByChild() method listed.

https://firebase.google.com/docs/reference/js/firebase.database.Reference#orderbychild

I also answered this in the Spring2019 Q&A, but I also wanted to put this here in case anyone needed this, but don't see it in the 2019 one.

answered by (1 point)
+1 vote

You can change the date to the number and store them in firebase, when you call it to sort by value then change them to the date

answered by (1 point)
+1

I used a firebase time stamp function to set a standard timeline for all the inputs.

...