Search code examples
dateswift3swiftdate

Hours between dates with SwiftDate


What's the easiest way to get number of hours between 2 dates with SwiftDate lib?

In this case hours could be days / minutes or whatever I'll need next time.

I see I can probably do (date1 - date2) / 60 * 60 but that just does not feel right.


Solution

  • In SwiftDate you can easily do

    (date1 - date2).in(.hour)