I have DatePicker Dialog, When I select date at that time I want to calculate age it\'s working but when I select date of current year at that time it showing the -1 age instead
Here is my solution in Kotlin:
import java.time.LocalDateTime
fun getAge(birthYear: Int, birthMonth: Int, birthDay: Int): Int {
var age: Int = LocalDateTime.now().year - birthYear
if (birthMonth > LocalDateTime.now().monthValue || birthMonth == LocalDateTime.now().monthValue && birthDay > LocalDateTime.now().dayOfMonth) { age-- }
if (age < 0) { age = 0 }
return age
}