I've a dates pickers, one for start date and one for end date, and my dates looks like this as string:
Start 2020-05-06
End 2020-05-08
My problem is, How can I calculate every time the differences?
For example, if the start date is 14/05, the end date can't be before 14/05.
Currently i've this check:
val from= calendar.clone()
if (isStarted) {
from.add(Calendar.DATE, -29)
} else {
val dayOfMonth: Int = extractDay(selectedStartDate)
from.add(Calendar.DATE, ??) //the problem, set the minimum date to start date
}
datePicker.minDate = from.timeInMillis
//Returning the day of startDate
private fun extractDay(selectedStartDate: String?): Int {
return selectedStartDate?.substring(selectedStartDate.length - 2)!!.toInt()
}
But there is 2 problems.
1) How can I calculate the differences?
2) If for example user picks start and end date, and then pick start again it could be that the start date will be after the end date, how can I prevent this?
UPDATE: Question 2 answered in the comments