How to get dates in two dates fscalendar,swift 3

Home / Uncategorized / How to get dates in two dates fscalendar,swift 3

How to get dates in two dates fscalendar,swift 3.

for example:

08-10-2017 -> Start Date

08-15-2017 -> End Date


should be like this ->








I want to get ranges in two specific date, can someone help me out please. I tried to put these two dates to for loop but no chance.

You need to create a calendar based dates, and start increasing start date until you reach end date. Here is a code snippet, how to do it:func showRange(between startDate: Date, and endDate: Date) {
// Make sure startDate is smaller, than endDate
guard startDate < endDate else { return } // Get the current calendar, i think in your case it should some fscalendar instance let calendar = Calendar.current // Calculate the endDate for your current calendar let calendarEndDate = calendar.startOfDay(for: endDate) // Lets create a variable, what we can increase day by day var currentDate = calendar.startOfDay(for: startDate) // Run a loop until we reach the end date while(currentDate <= calendarEndDate) { // Print the current date print(currentDate) // Add one day at the time currentDate = .day, value: 1, to: currentDate)! } } Usage:let today = Date() let tenDaysLater = .day, value: 10, to: today)! showRange(between: today, and: tenDaysLater) Read more

Leave a Reply

Your email address will not be published. Required fields are marked *