- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get the differences between two dates in iOS?
Getting difference between two dates is easy. You should know how to play between the dates.
We will be using DateFormatter class for formatting the dates.
You can read more about it here
We will also be using Calendar structure, apple has provided beautiful documentation of it,
So let’s get started.
Open Xcode, New Playground.
Copy the below code
import UIKit // create object of DateFormatter and Calendar let formatter = DateFormatter() let calendar = Calendar.current // specify the format, formatter.dateFormat = "dd-MM-yyyy" // specify the start date let startDate = formatter.date(from: "10-08-2018") // specify the end date let endDate = formatter.date(from: "23-09-2019") print(startDate!) print(endDate!) let diff = calendar.dateComponents([.day], from: startDate!, to: endDate!) // print the diff between the two dates print(diff)
- How to get the differences between two dates in Android using Kotlin?
- How to get the difference between two dates in Android?
- C# Program to get the difference between two dates
- Not able to get the difference between two dates (SAP)
- C# Program to get the difference between two dates in seconds
- How to get number of quarters between two dates in Java
- How to get the distance between two geographic locations in iOS using Swift?
- Get the SUM of records between two given dates in MySQL
- How to query between two dates in MySQL?
- How to create a vector with dates between two dates in R?
- How to count days between two dates in Java