Firebase Endat() Not Working with Date String

Query startAt and endAt for a date in firebase

Change this:

const getAttendCount = fDB.ref(`organization/${uid}/attendance`)
.orderByChild('attendance')

Into this:

const getAttendCount = fDB.ref(`organization/${uid}/attendance`)
.orderByKey()

The reason you need to use orderByKey() is because the date are acting as a key and not as a child which would have a value example:

"name" : "peter"

Firebase query equalTo() or startAt().endAt() stop working

I fix-it,It was the query, was missing "orderBychild()" field, most probable I mistakenly deleted otherwise cannot explain-it :))

Firebase Android - startAt() and endAt() not working correctly?

You almost done right but you should add addListenerForSingleValueEvent after the database reference that already apply orderBy() , startAt(), endAt() like this.

 usersRef.orderByChild("username")
.startAt(queryText)
.endAt(queryText+"\uf8ff")
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
searchList = new ArrayList<>();
for (DataSnapshot postSnapshot: snapshot.getChildren()) {
User user = postSnapshot.getValue(User.class);
Log.d("USER: ", "" + user.getUsername());

searchList.add(user);
}

adapter = new UserCardAdapter(getContext(), searchList);
recyclerView.setAdapter(adapter);
}

@Override
public void onCancelled(DatabaseError databaseError) {
Log.e("onQueryTextChange: " ,databaseError.getMessage());
}
});

startAt' and 'endAt' is not filtering the data using angularfire2 4.0.0

The string format in which you store the dates is not easily sortable. Since Firebase does a string comparison on these strings, they don't match your intended result. This is easiest to see if we reproduce the problem in plain JavaScript, without Firebase being involved:

var dates = [  "18-2-2018",  "18-3-2018"];
var dateFrom = "3-3-2018" , dateTo = "31-3-2018" ; dates.forEach(function(date) { if (date < dateFrom) console.log(date+" is before "+dateFrom); if (date > dateFrom) console.log(date+" is after "+dateFrom); if (date < dateTo) console.log(date+" is before "+dateTo); if (date > dateTo) console.log(date+" is after "+dateTo); if (date >= dateFrom && date <= dateTo) console.log(date+" is within range");});

endAt() with limitToLast() in Firebase query is not working as expected in android

The time property in your database is a numeric value, but in your code you're passing it as a string. When the database compares a number and a string, they are never the same.

So you'll want to fix your code so that is also treats the time as a number, or at the very least pass is as a number to the database by calling toDouble() on it.

Firebase Realtime Database Date String Range with Dart

You're looking for orderByKey():

_database.reference()
.child(DAY_TABLE)
.child(UserState.instance.user.uid)
.orderByKey()
.startAt("2020-09-12")
.endAt("2020-09-19")

Why doesn't the firebase query look like list?

You store the date/time in your database in a string value, in the format dd/MM/yyyy hh:mm:ss. Strings in Firebase are lexicographically ordered, and unfortunately in the date format you use, the lexicographical order and the chronological order of the values are different.

The solution is to store the date/time value in a format that does allow it to be sorted in the way you want. The two most common ways are to store them as a timestamp (a numeric value that is the number of milliseconds since a specific date), or in a sortable string format (typically 2018-10-20T16:34:34).

For more on this, see:

  • Firebase query by date string
  • Firebase endAt() not working with date string?


Related Topics



Leave a reply



Submit