Skip to main content

Date Validators

Date validators check date and time values after mutators have been applied. They validate ranges, times, ages, weekdays, and more.


All Validators


Date Comparison

min(dateOrField)

Date must be greater than or equal to the given date or field (inclusive)

v.date().min('2024-01-01')     // Value comparison
v.date().min(new Date()) // Value comparison
v.date().min('startsAt') // Field comparison
// Input: "2024-12-25" → Valid ✅
// Input: "2023-12-25" → Invalid ❌

max(dateOrField)

Date must be less than or equal to the given date or field (inclusive)

v.date().max('2024-12-31')     // Value comparison
v.date().max('endsAt') // Field comparison
// Input: "2024-12-25" → Valid ✅
// Input: "2025-01-01" → Invalid ❌

before(dateOrField)

Date must be strictly less than the given date or field (exclusive)

v.date().before('2024-12-31')
// Input: "2024-12-30" → Valid ✅
// Input: "2024-12-31" → Invalid ❌

after(dateOrField)

Date must be strictly greater than the given date or field (exclusive)

v.date().after('2024-01-01')
// Input: "2024-01-02" → Valid ✅
// Input: "2024-01-01" → Invalid ❌

between(startDate, endDate)

Date must be between start and end dates

v.date().between(new Date('2024-01-01'), new Date('2024-12-31'))
// Input: "2024-06-15" → Valid ✅
// Input: "2023-12-31" → Invalid ❌

today()

Date must be exactly today

v.date().today()
// Input: Today's date → Valid ✅
// Input: Yesterday's date → Invalid ❌

fromToday()

Date must be today or in the future

v.date().fromToday()
// Input: Today or future date → Valid ✅
// Input: Past date → Invalid ❌

beforeToday()

Date must be before today

v.date().beforeToday()
// Input: Past date → Valid ✅
// Input: Today or future date → Invalid ❌

afterToday()

Date must be after today (not including today)

v.date().afterToday()
// Input: Future date → Valid ✅
// Input: Today or past date → Invalid ❌

past()

Date must be in the past

v.date().past()
// Input: Past date → Valid ✅
// Input: Today or future date → Invalid ❌

future()

Date must be in the future

v.date().future()
// Input: Future date → Valid ✅
// Input: Today or past date → Invalid ❌

Time Validation

fromHour(hour)

Time must be from specific hour onwards (0-23)

v.date().fromHour(9)
// Input: "2024-12-25 09:00" → Valid ✅
// Input: "2024-12-25 08:00" → Invalid ❌

beforeHour(hour)

Time must be before specific hour (0-23)

v.date().beforeHour(17)
// Input: "2024-12-25 16:00" → Valid ✅
// Input: "2024-12-25 17:00" → Invalid ❌

betweenHours(startHour, endHour)

Time must be between start and end hours (0-23)

v.date().betweenHours(9, 17)
// Input: "2024-12-25 14:00" → Valid ✅
// Input: "2024-12-25 08:00" → Invalid ❌

fromMinute(minute)

Time must be from specific minute onwards (0-59)

v.date().fromMinute(30)
// Input: "2024-12-25 14:30" → Valid ✅
// Input: "2024-12-25 14:29" → Invalid ❌

beforeMinute(minute)

Time must be before specific minute (0-59)

v.date().beforeMinute(45)
// Input: "2024-12-25 14:44" → Valid ✅
// Input: "2024-12-25 14:45" → Invalid ❌

betweenMinutes(startMinute, endMinute)

Time must be between start and end minutes (0-59)

v.date().betweenMinutes(30, 45)
// Input: "2024-12-25 14:35" → Valid ✅
// Input: "2024-12-25 14:20" → Invalid ❌

betweenTimes(startTime, endTime)

Time must be between start and end times (HH:MM format)

v.date().betweenTimes('09:00', '17:00')
// Input: "2024-12-25 14:30" → Valid ✅
// Input: "2024-12-25 08:00" → Invalid ❌

Age Validation

age(years)

Age must be exactly the given years

v.date().age(18)
// Input: Date 18 years ago → Valid ✅
// Input: Date 17 years ago → Invalid ❌

minAge(years)

Minimum age requirement

v.date().minAge(18)
// Input: Date 18+ years ago → Valid ✅
// Input: Date 17 years ago → Invalid ❌

maxAge(years)

Maximum age requirement

v.date().maxAge(65)
// Input: Date 65 or less years ago → Valid ✅
// Input: Date 66 years ago → Invalid ❌

betweenAge(minAge, maxAge)

Age must be between min and max years

v.date().betweenAge(18, 65)
// Input: Date 18-65 years ago → Valid ✅
// Input: Date 17 years ago → Invalid ❌

birthday(minAge?, maxAge?)

Valid birthday (not in future, reasonable age)

v.date().birthday(18, 120)
// Input: Valid birthday → Valid ✅
// Input: Future date → Invalid ❌

Day Validation

weekDay(day)

Date must be specific weekday

v.date().weekDay('monday')
// Input: Monday → Valid ✅
// Input: Tuesday → Invalid ❌

weekdays(days)

Date must be one of specified weekdays

v.date().weekdays(['monday', 'wednesday', 'friday'])
// Input: Monday → Valid ✅
// Input: Tuesday → Invalid ❌

weekend()

Date must be a weekend (Saturday or Sunday)

v.date().weekend()
// Input: Saturday or Sunday → Valid ✅
// Input: Monday → Invalid ❌

businessDay()

Date must be a business day (Monday-Friday)

v.date().businessDay()
// Input: Monday-Friday → Valid ✅
// Input: Saturday → Invalid ❌

format(format)

Date must match specific format

v.date().format('YYYY-MM-DD')
// Input: "2024-12-25" → Valid ✅
// Input: "25/12/2024" → Invalid ❌

Period Validation

month(month)

Date must be in specific month (1-12)

v.date().month(12)
// Input: December → Valid ✅
// Input: November → Invalid ❌

year(year)

Date must be in specific year

v.date().year(2024)
// Input: 2024 → Valid ✅
// Input: 2023 → Invalid ❌

betweenYears(startYear, endYear)

Date must be between start and end years. Smart detection: number or field name.

v.date().betweenYears(2020, 2030)           // Value comparison
v.date().betweenYears('startYear', 'endYear') // Field comparison
// Input: 2024 → Valid ✅
// Input: 2019 → Invalid ❌

betweenMonths(startMonth, endMonth)

Date must be between start and end months (1-12). Smart detection: number or field name.

v.date().betweenMonths(6, 9)                    // Value comparison
v.date().betweenMonths('startMonth', 'endMonth') // Field comparison
// Input: July-August-September → Valid ✅
// Input: May → Invalid ❌

betweenDays(startDay, endDay)

Date must be between start and end days (1-31). Smart detection: number or field name.

v.date().betweenDays(1, 15)                 // Value comparison
v.date().betweenDays('startDay', 'endDay') // Field comparison
// Input: Day 10 → Valid ✅
// Input: Day 20 → Invalid ❌

minYear(yearOrField)

Year must be greater than or equal to given year or field. Smart detection: number or field name.

v.date().minYear(2024)           // Value comparison
v.date().minYear('startYear') // Field comparison
// Input: 2024 or later → Valid ✅
// Input: 2023 → Invalid ❌

maxYear(yearOrField)

Year must be less than or equal to given year or field. Smart detection: number or field name.

v.date().maxYear(2030)           // Value comparison
v.date().maxYear('endYear') // Field comparison
// Input: 2030 or earlier → Valid ✅
// Input: 2031 → Invalid ❌

minMonth(monthOrField)

Month must be greater than or equal to given month or field (1-12). Smart detection: number or field name.

v.date().minMonth(6)             // Value comparison
v.date().minMonth('startMonth') // Field comparison
// Input: June or later → Valid ✅
// Input: May → Invalid ❌

maxMonth(monthOrField)

Month must be less than or equal to given month or field (1-12). Smart detection: number or field name.

v.date().maxMonth(9)             // Value comparison
v.date().maxMonth('endMonth') // Field comparison
// Input: September or earlier → Valid ✅
// Input: October → Invalid ❌

minDay(dayOrField)

Day must be greater than or equal to given day or field (1-31). Smart detection: number or field name.

v.date().minDay(1)               // Value comparison
v.date().minDay('startDay') // Field comparison
// Input: Day 1 or later → Valid ✅
// Input: Day 0 → Invalid ❌

maxDay(dayOrField)

Day must be less than or equal to given day or field (1-31). Smart detection: number or field name.

v.date().maxDay(31)              // Value comparison
v.date().maxDay('endDay') // Field comparison
// Input: Day 31 or earlier → Valid ✅
// Input: Day 32 → Invalid ❌

quarter(quarter)

Date must be in specific quarter (1-4)

v.date().quarter(4)
// Input: Q4 (Oct-Dec) → Valid ✅
// Input: Q1 (Jan-Mar) → Invalid ❌

leapYear()

Date must be in a leap year

v.date().leapYear()
// Input: 2024 (leap year) → Valid ✅
// Input: 2023 (not leap year) → Invalid ❌

Relative Date Validation

withinDays(days)

Date must be within X days from now (past or future)

v.date().withinDays(7)
// Input: Within 7 days → Valid ✅
// Input: 8+ days away → Invalid ❌

withinPastDays(days)

Date must be within X days in the past

v.date().withinPastDays(7)
// Input: Within last 7 days → Valid ✅
// Input: 8+ days ago → Invalid ❌

withinFutureDays(days)

Date must be within X days in the future

v.date().withinFutureDays(7)
// Input: Within next 7 days → Valid ✅
// Input: 8+ days away → Invalid ❌

Field Comparison

sameAsField(field)

Date must be the same as another field's date

v.date().sameAsField('startDate')
// Input: Same as startDate → Valid ✅
// Input: Different from startDate → Invalid ❌

sameAsFieldSibling(field)

Date must be the same as another sibling field's date

v.date().sameAsFieldSibling('startDate')
// Input: Same as sibling startDate → Valid ✅
// Input: Different from sibling startDate → Invalid ❌

minSibling(field)

Date must be greater than or equal to sibling field value (inclusive)

v.date().minSibling('startDate')
// Input: greater than or equal to startDate → Valid ✅
// Input: less than startDate → Invalid ❌

maxSibling(field)

Date must be less than or equal to sibling field value (inclusive)

v.date().maxSibling('endDate')
// Input: less than or equal to endDate → Valid ✅
// Input: greater than endDate → Invalid ❌

beforeSibling(field)

Date must be less than sibling field value (exclusive)

v.date().beforeSibling('endDate')
// Input: less than endDate → Valid ✅
// Input: greater than or equal to endDate → Invalid ❌

afterSibling(field)

Date must be greater than sibling field value (exclusive)

v.date().afterSibling('startDate')
// Input: greater than startDate → Valid ✅
// Input: less than or equal to startDate → Invalid ❌

betweenYearsSibling(startYearField, endYearField)

Date must be between sibling field years

v.date().betweenYearsSibling('startYear', 'endYear')
// Input: Year between sibling startYear and endYear → Valid ✅
// Input: Year outside range → Invalid ❌

betweenMonthsSibling(startMonthField, endMonthField)

Date must be between sibling field months

v.date().betweenMonthsSibling('startMonth', 'endMonth')
// Input: Month between sibling startMonth and endMonth → Valid ✅
// Input: Month outside range → Invalid ❌

betweenDaysSibling(startDayField, endDayField)

Date must be between sibling field days

v.date().betweenDaysSibling('startDay', 'endDay')
// Input: Day between sibling startDay and endDay → Valid ✅
// Input: Day outside range → Invalid ❌

minYearSibling(field)

Year must be greater than or equal to sibling field year

v.date().minYearSibling('startYear')
// Input: Year greater than or equal to sibling startYear → Valid ✅
// Input: Year less than sibling startYear → Invalid ❌

maxYearSibling(field)

Year must be less than or equal to sibling field year

v.date().maxYearSibling('endYear')
// Input: Year less than or equal to sibling endYear → Valid ✅
// Input: Year greater than sibling endYear → Invalid ❌

minMonthSibling(field)

Month must be greater than or equal to sibling field month

v.date().minMonthSibling('startMonth')
// Input: Month greater than or equal to sibling startMonth → Valid ✅
// Input: Month less than sibling startMonth → Invalid ❌

maxMonthSibling(field)

Month must be less than or equal to sibling field month

v.date().maxMonthSibling('endMonth')
// Input: Month less than or equal to sibling endMonth → Valid ✅
// Input: Month greater than sibling endMonth → Invalid ❌

minDaySibling(field)

Day must be greater than or equal to sibling field day

v.date().minDaySibling('startDay')
// Input: Day greater than or equal to sibling startDay → Valid ✅
// Input: Day less than sibling startDay → Invalid ❌

maxDaySibling(field)

Day must be less than or equal to sibling field day

v.date().maxDaySibling('endDay')
// Input: Day less than or equal to sibling endDay → Valid ✅
// Input: Day greater than sibling endDay → Invalid ❌

Examples

Birth Date Validation

const birthDateSchema = v.date()
.required()
.beforeToday()
.maxAge(120);

const result = await validate(birthDateSchema, '1990-01-01');
// Result: { isValid: true, data: Date('1990-01-01') }

Event Date Validation

const eventDateSchema = v.date()
.required()
.fromToday()
.after('2024-01-01');

const result = await validate(eventDateSchema, '2024-12-25');
// Result: { isValid: true, data: Date('2024-12-25') }

Appointment Time Validation

const appointmentSchema = v.date()
.required()
.fromToday()
.betweenHours(9, 17);

const result = await validate(appointmentSchema, '2024-12-25 14:30');
// Result: { isValid: true, data: Date('2024-12-25 14:30') }

Age Verification

const ageSchema = v.date()
.required()
.beforeToday()
.minAge(18)
.maxAge(65);

const result = await validate(ageSchema, '1990-01-01');
// Result: { isValid: true, data: Date('1990-01-01') }

Date Range Validation

const dateRangeSchema = v.date()
.required()
.between(new Date('2024-01-01'), new Date('2024-12-31'));

const result = await validate(dateRangeSchema, '2024-06-15');
// Result: { isValid: true, data: Date('2024-06-15') }

See Also