daysUntil

actual fun LocalDate.daysUntil(other: LocalDate): Int(source)
fun Instant.daysUntil(other: Instant, timeZone: TimeZone): Int(source)

Returns the number of whole days between two instants in the specified timeZone.

If the result does not fit in Int, returns Int.MAX_VALUE for a positive result or Int.MIN_VALUE for a negative result.

See also

Throws

if this or other instant is too large to fit in LocalDateTime.

Samples

import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.random.*
import kotlin.test.*
import kotlin.time.Duration.Companion.hours

fun main() { 
   //sampleStart 
   // Finding the number of full days between two instants in the given time zone
val startInstant = Instant.parse("2023-03-26T00:30:00Z")
val endInstant = Instant.parse("2023-03-28T00:15:00Z")
// In New York, these days are both 24 hour long, so the difference is 15 minutes short of 2 days
val daysBetweenInNewYork = startInstant.daysUntil(endInstant, TimeZone.of("America/New_York"))
check(daysBetweenInNewYork == 1)
// In Berlin, 2023-03-26 is 23 hours long, so the difference more than 2 days
val daysBetweenInBerlin = startInstant.daysUntil(endInstant, TimeZone.of("Europe/Berlin"))
check(daysBetweenInBerlin == 2) 
   //sampleEnd
}

expect fun LocalDate.daysUntil(other: LocalDate): Int(source)

Returns the number of whole days between two dates.

The value is rounded toward zero.

If the result does not fit in Int, returns Int.MAX_VALUE for a positive result or Int.MIN_VALUE for a negative result.

See also

Samples

import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.random.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   // Finding how many days have passed between two dates
val dateOfConcert = LocalDate(2024, Month.SEPTEMBER, 26)
val today = LocalDate(2024, Month.APRIL, 16)
val daysUntilConcert = today.daysUntil(dateOfConcert)
check(daysUntilConcert == 163) 
   //sampleEnd
}
actual fun LocalDate.daysUntil(other: LocalDate): Int(source)
actual fun LocalDate.daysUntil(other: LocalDate): Int(source)