previous
Returns a LocalDate that has the given dayOfWeek earlier than this date.
If the dayOfWeek is already the one this date has, a date one week earlier will be returned. See previousOrSame for a version that returns the date unchanged if it's already on the given dayOfWeek.
See also
Samples
import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.random.*
import kotlin.test.*
fun main() {
//sampleStart
val today = LocalDate(2026, 2, 14)
check(today.dayOfWeek == DayOfWeek.SATURDAY)
// Find the end of the Monday-based week that doesn't contain the given date.
val endOfPreviousMondayBasedWeek = today.previous(DayOfWeek.SUNDAY)
check(endOfPreviousMondayBasedWeek == LocalDate(2026, 2, 8))
// Find the end of the Sunday-based week that doesn't contain the given date.
val endOfPreviousSundayBasedWeek = today.previous(DayOfWeek.SATURDAY)
check(endOfPreviousSundayBasedWeek == LocalDate(2026, 2, 7))
//sampleEnd
}Content copied to clipboard