I have two dates: initial and final. I need to be able to quickly get all the interim days, given the month. The problem is that every digit in the date is due to a variable. The reason of it is that I use Date Picker with range, but all values are given separately (like startDay, startMonth, startYear and endDay, endMonth, endYear). So, I need to get all dates between those dates. It must look like this:
"24/02/2018|25/02/2018|26/02/2018|27/02/2018|28/02/2018|01/03/2018"
Look at this: 01/03/2018.
SOLUTION:
fun getDaysBetweenDates(startdate: Date, enddate: Date): List<String> {
val dates = ArrayList<String>()
val calendar = GregorianCalendar()
calendar.time = startdate
while (calendar.time.before(enddate)) {
val result = calendar.time
val formatter = SimpleDateFormat("dd/MM/yyyy")
val today = formatter.format(result)
today.split("|")
dates.add(today)
calendar.add(Calendar.DATE, 1)
}
return dates
}
Well, thanks for helping to OleV.V. and asm0dey.