ios - FSCalendar: how to get dates in two dates? -


i using swift 3, , print every day between 2 dates.

for example:

08-10-2017 -> start date

08-15-2017 -> end date

should print:

08-10-2017

08-11-2017

08-12-2017

08-13-2017

08-14-2017

08-15-2017

i want ranges in 2 specific date, can me out please. tried put these 2 dates loop no chance.

you need create calendar based dates, , start increasing start date until reach end date. here code snippet, how it:

func showrange(between startdate: date, , enddate: date) {     // make sure startdate smaller, enddate     guard startdate < enddate else { return }      // current calendar, think in case should fscalendar instance     let calendar = calendar.current     // calculate enddate current calendar     let calendarenddate = calendar.startofday(for: enddate)      // lets create variable, can increase day day     var currentdate = calendar.startofday(for: startdate)      // run loop until reach end date     while(currentdate <= calendarenddate) {         // print current date         print(currentdate)         // add 1 day @ time         currentdate = calendar.current.date(byadding: .day, value: 1, to: currentdate)!           } } 

usage:

let today = date() let tendayslater = calendar.current.date(byadding: .day, value: 10, to: today)! showrange(between: today, and: tendayslater) 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -