Get items from array by the nearest day

I'm adding items to my Firebase with date in this format:

var date: NSDate?

 override func viewDidLoad() {
        super.viewDidLoad()
        date = NSDate()
}

// ......
    @IBAction func save(_ sender: UIBarButtonItem) {
if let realDate = date {
            fullDate = "\(String(describing: realDate))"
        }
// ......
let wordItem = Word(word: word, translation: translation, date: fullDate, fullDate: trueDate, exOne: exOne, exTwo: exTwo, completed: false, keyRandom: randomString)
        let wordItemRef = self.ref?.child("Users").child(uid).child("LearnedWords").child(randomString)
        wordItemRef?.setValue(wordItem.toAnyObject())
        presentingViewController?.dismiss(animated: true, completion: nil)
}

So, my Firebase for Date looks like this:

enter image description here

Then, I retrieve this data in another ViewController and add it to the array:

override func viewDidLoad() {
    super.viewDidLoad()

    // checking if user is in
    guard let uid = Auth.auth().currentUser?.uid else {
        return
    }

    // retrieving data from FireBase
    ref = Database.database().reference()
    databaseHandle = ref?.child("Users").child(uid).child("LearnedWords").observe(.value, with: { (snapshot) in
        var newItems: [Word] = []
        for item in snapshot.children {
            let wordItem = Word(snapshot: item as! DataSnapshot)
            newItems.append(wordItem)
        }
        newItems.sort(by: { $0.date.compare($1.date) == .orderedDescending})
        self.words = newItems
        self.getAllMessagesSent(snapshot: newItems)
    })
}
// retrieve data from Firebase to the View
    func getAllMessagesSent(snapshot: [Word]) {
        int = snapshot.count - 1
        array = snapshot
    }

The question:

How is it possible to retrieve the items from array from the nearest day? If today is 16 of August, I should get all items of the nearest day (for example, 8 items from 12 of August, if this date was the last). And should I change the way I'm adding date to Firebase to achieve this?

Edit

I achieved this by comparing the last date in the array with all other dates:

// retrieve data from Firebase to the View
var dateToCompare: String?
var array: [Word] = []

func getAllMessagesSent(snapshot: [Word]) {
    int = snapshot.count - 1
    array = snapshot

    let dateFormatter = DateFormatter()
    dateFormatter.dateFormat = "MM/dd/yyyy"
    dateFormatter.timeZone = TimeZone(secondsFromGMT: 0)

    // get the nearest item's date and convert it to Date
    dateToCompare = array[0].fullDate
    let formattedDateToCompare = dateFormatter.date(from: dateToCompare!)

    // make array of dates
    var dateArray = [NSDate]()
    var numberOfWordsThisDay = 1

    // formatting all dates in the array
    for i in 0..<array.count {
        let date1 = dateFormatter.date(from:  array[i].fullDate)
        dateArray.append(date1! as NSDate)
    }

    // comparing and in case of cussces increase the number
    for i in 1..<array.count {
        if Calendar.current.compare(formattedDateToCompare!, to: dateArray[i] as Date, toGranularity: .day) == .orderedSame {
            numberOfWordsThisDay += 1
        }
    }
    self.numOfWords.placeholder = "From \(numberOfWordsThisDay) to \(array.count)"
}

It works, but it definitely doesn't look like efficient solution, because I loop over two huge arrays. Is it possible to improve my code? Thanks!