If your algorithm cannot find a date, it is easier to raise an Exception than to return ''. Returning sentinel values instead of exceptions can lead to unexpected behaviour if the user of this function does not test for this sentinel value.
Comments should explain why you did something, not how. # Take the last four digits tells you ...
Any better/simple solution to do this ?
Yes. Functionality now built-in.
java.time.LocalDate::datesUntil ➙ Stream of LocalDate objects
The modern approach uses java.time classes.
The java.time.LocalDate has built-in support for generating a stream of dates. Call LocalDate::datesUntil.
I do not know Scala, so here is Java syntax.
LocalDate today = ...