Gurmukh Singh
Gurmukh Singh

Reputation: 2017

Firebase - get user based on date

I have a User model which contain a field:

var created_on: Double?

and when the user signs up it gets assigned:

Date().timeIntervalSince1970

and i want to get the users who joined today, at the moment i have something like:

Firestore.firestore().collection("users")
      .whereField("activated", isEqualTo: 1)
      .whereField("city", isEqualTo: loggedInUser.city)
      .getDocuments{(snapshot, error) in
      guard let snap = snapshot else {
          return
      }

Im trying to have something like this (pseudo):

.whereField("created_on", isEqualTo: today)

Upvotes: 0

Views: 54

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598765

Since you storing timestamp, your query actually is selecting a range:

.whereField("created_on", isGreaterThanOrEqualTo: startOfToday)
.whereField("created_on", isLessThan: startOfTomorrow)

Where startOfToday and startOfTomorrow are the TimeInterval/Double values for the start of today and tomorrow respectively.

Upvotes: 1

Related Questions