Blog Post
Sian_Ayres
Quantexa Team
11 months agoSomething Important to Note when using Period.Between
If we have these 2 dates and use Period.between:
val fromDate = LocalDate.parse("2020-01-01")
val toDate = LocalDate.parse("2022-02-15")
Period.between(fromDate, toDate)Copy
Running this will return Period(years = 2, months = 1, days = 14).
If we then use .getDays this would return "14" and not "776".
If you want to calculate the days between 2 dates the better method is to use the DAYS.between function:
ChronoUnit.DAYS.between(fromDate, toDate)
This page explains this better: https://www.baeldung.com/scala/difference-between-two-dates