Swift Calendar favorites

3 December 2025

The Calendar class in Swift has so many useful helper methods to make working with dates easier, and less error prone. A couple of my absolute favorites:

isDateInToday(_ date: Date) -> Bool

Simple and to the point.

let occursToday = Calendar.current.isDateInToday(someDate)

isDate(_ date1: Date, inSameDayAs date2: Date) -> Bool

Say you have two dates returned from a server as UNIX timestamps, and want to check if they represent the same date. You could parse them into date componenets (which is another great feature of Calendar), and compare the year, month, and day. Or use the simple one-liner:

let date = Date(timeIntervalSince1970: 1764636075)
let anotherDate = Date(timeIntervalSince1970: 1764596475)
let isTheSameDay = Calendar.current.isDate(date, inSameDayAs: anotherDate)

It’s just as easy to resolve the match to a given hour, month, or any other component.

let isInTheSameHour = Calendar.current.isDate(date, equalTo: anotherDate, toGranularity: .hour)