Created
July 8, 2018 19:35
-
-
Save sdpatil/b4cd8d89a77e401ec1c7d99748f8bb11 to your computer and use it in GitHub Desktop.
Generate days between 2 dates in scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.time.LocalDate | |
import java.time.temporal.ChronoUnit | |
def generateDaysBetween(startDateStr: String, endDateStr:String)={ | |
val start = LocalDate.parse(startDateStr) | |
val end = LocalDate.parse(endDateStr) | |
val between = ChronoUnit.DAYS.between(start,end).toInt | |
for(daysPlus <- 0 to between) | |
yield start.plusDays(daysPlus) | |
} | |
generateDaysBetween("2018-07-03","2018-07-25").foreach(println) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment