I have two date like this current date 2019-10-09 birthday date 2000-01-01
How can I recognize, that currentdate - birthdaydate will be more than 18 years ?
I have two date like this current date 2019-10-09 birthday date 2000-01-01
How can I recognize, that currentdate - birthdaydate will be more than 18 years ?
Have a look at this question:
Finding days difference between dates in Android Kotlin.
Can easily be modified to get the year difference between dates.
import java.time.LocalDateTime
import java.time.temporal.ChronoUnit
fun main(args : Array<String>) {
val start = "2019-05-24 14:17:00"
val end = "2019-09-13 14:15:51"
daysBetweenDates(start, end)
}
fun daysBetweenDates(start: String, end: String) {
val format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
val mStart = LocalDateTime.parse(start, format)
val mEnd = LocalDateTime.parse(end, format)
val difference = ChronoUnit.Years.between(mStart, mEnd)
println("START => $mStart")
println("END => $mEnd")
println("DIFFERENCE => $difference in years"}
}