I am trying to pass today\'s date in Firestore Timestamp
in my app. I am getting the today\'s date like this
formatter.dateFormat = \"MMMM d, yyyy\"
You need:
1) Convert String -> Date
2) Convert Date -> Timestamp (FIRTimestamp)
formatter.dateFormat = "MMMM d, yyyy HH:mm:ss"
let startTime: Date = formatter.date(from: startDate) ?? Date(timeIntervalSince1970: 0)
let startTimestamp: Timestamp = Timestamp(date: startTime)
let endTime: Date = formatter.date(from: endDate) ?? Date()
let endTimestamp: Timestamp = Timestamp(date: endTime)
3) Change func to:
self.db.collection("Locations")
.whereField("userid", isEqualTo: "\(selectedUserID)")
.whereField("createddatetime", isGreaterThanOrEqualTo: startTimestamp)
.whereField("createddatetime", isLessThanOrEqualTo: endTimestamp)
.getDocuments() { (snapshot, error) in
...
}