Nagaraj Hegde
05/20/2024, 7:34 AMval dt1= LocalDate(2024,5,15)
val dt2 = LocalDate(2024,2,23)
How to find the difference in number of days?Stylianos Gakis
05/20/2024, 7:39 AMNagaraj Hegde
05/20/2024, 7:47 AMval dt1= LocalDate(2024,5,15)
val dt2 = LocalDate(2024,2,23)
val rdf = dt1.minus(dt2)
println(rdf)
What I get in the console is: P2M22D , which I think must be referring to 2 months, 22 days. However, that is not an absolute number, since two months could mean different for different months. How do I get it in absolute days?Stylianos Gakis
05/20/2024, 8:03 AMDatePeriod
object right?
https://github.com/Kotlin/kotlinx-datetime/blob/bc8adee2b9e3659e8e1c38fc09f3a4a1bdf85276/core/common/src/DateTimePeriod.kt#L430
This seems to show that it has a val days: Int
value in there you can grab.Nagaraj Hegde
05/20/2024, 9:34 AMval dt1= LocalDate(2024,5,15)
val dt2 = LocalDate(2024,2,23)
val rdf = dt2.daysUntil(dt1)
val rdf2 = dt2.daysUntil(dt1)
println(rdf)
Now it prints 82.
Thank you @Stylianos Gakis so much for guiding & pointing to the right source. This helped me a lot!Stylianos Gakis
05/20/2024, 9:38 AMThat only provides the days as in remainder days after monthAh I see, it was a guess after all 😅 Awesome to see it work!
mbonnin
05/26/2024, 12:14 PM