DEV Community

taijidude
taijidude

Posted on

Check if date is between two other dates

A small method to check if a LocalDataTime is in a Range between to other LocalDateTime - Objects.

private boolean isInDateRange(
                        LocalDateTime upper,
                        LocalDateTime lower,
                        LocalDateTime toCheck) {
    var isUpper = toCheck.equals(upper);
    var isLower = toCheck.equals(lower);
    if (isLower || isUpper) {
        return true;
    }
    return toCheck.isBefore(upper) && toCheck.isAfter(lower);
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)