Query Methods
Check date relationships, validate dates, and compare them.
Basic Comparisons
Section titled “Basic Comparisons”isBefore()
Section titled “isBefore()”Check if a date is before another date:
const date1 = daytime('2025-11-15')const date2 = daytime('2025-11-20')
date1.isBefore(date2)// true
date2.isBefore(date1)// false
date1.isBefore(date1)// false
// Compare with unit precisiondate1.isBefore(date2, 'month')// false (same month)
date1.isBefore(date2, 'day')// true (different day)isAfter()
Section titled “isAfter()”Check if a date is after another date:
const date1 = daytime('2025-11-15')const date2 = daytime('2025-11-20')
date1.isAfter(date2)// false
date2.isAfter(date1)// true
// With unitdate2.isAfter(date1, 'month')// false (same month)
date2.isAfter(date1, 'day')// true (different day)isSame()
Section titled “isSame()”Check if dates are the same:
const date1 = daytime('2025-11-15T14:30:45Z')const date2 = daytime('2025-11-15T14:30:45Z')
date1.isSame(date2)// true
date1.isSame(date2, 'day')// true
date1.isSame(date2, 'month')// true
date1.isSame(date2, 'year')// true
date1.isSame(date2, 'hour')// true
date1.isSame(date2, 'minute')// true
date1.isSame(date2, 'second')// trueisSameOrBefore()
Section titled “isSameOrBefore()”Check if date is same or before:
const date1 = daytime('2025-11-15')const date2 = daytime('2025-11-15')const date3 = daytime('2025-11-20')
date1.isSameOrBefore(date2)// true
date1.isSameOrBefore(date3)// true
date3.isSameOrBefore(date1)// falseisSameOrAfter()
Section titled “isSameOrAfter()”Check if date is same or after:
const date1 = daytime('2025-11-15')const date2 = daytime('2025-11-15')const date3 = daytime('2025-11-10')
date1.isSameOrAfter(date2)// true
date1.isSameOrAfter(date3)// true
date3.isSameOrAfter(date1)// falseRange Checks
Section titled “Range Checks”isBetween()
Section titled “isBetween()”Check if date is between two dates (inclusive):
const date = daytime('2025-11-15')const start = daytime('2025-11-01')const end = daytime('2025-11-30')
date.isBetween(start, end)// true (date is between start and end)
date.isBetween(end, start)// false (start must be before end)
// With unit precision - compares only the specified unitdate.isBetween(start, end, 'month')// true (same month)
date.isBetween(start, end, 'day')// true (same day range)Relative Checks
Section titled “Relative Checks”isToday()
Section titled “isToday()”Check if date is today:
daytime().isToday()// true
daytime('2025-11-15').isToday()// false (if not today)isYesterday()
Section titled “isYesterday()”Check if date is yesterday:
daytime().subtract(1, 'day').isYesterday()// true
daytime('2025-11-14').isYesterday()// depends on current dateisTomorrow()
Section titled “isTomorrow()”Check if date is tomorrow:
daytime().add(1, 'day').isTomorrow()// true
daytime('2025-11-16').isTomorrow()// depends on current dateisPast()
Section titled “isPast()”Check if date is in the past:
daytime().subtract(1, 'day').isPast()// true
daytime().add(1, 'day').isPast()// false
daytime('2024-01-01').isPast()// trueisFuture()
Section titled “isFuture()”Check if date is in the future:
daytime().add(1, 'day').isFuture()// true
daytime().subtract(1, 'day').isFuture()// false
daytime('2026-01-01').isFuture()// trueSame Period Checks
Section titled “Same Period Checks”isSameDay()
Section titled “isSameDay()”Check if dates are the same day:
const date1 = daytime('2025-11-15T08:00:00')const date2 = daytime('2025-11-15T20:00:00')
date1.isSameDay(date2)// true (same day, different times)isSameMonth()
Section titled “isSameMonth()”Check if dates are in the same month:
const date1 = daytime('2025-11-15')const date2 = daytime('2025-11-30')
date1.isSameMonth(date2)// trueisSameYear()
Section titled “isSameYear()”Check if dates are in the same year:
const date1 = daytime('2025-01-15')const date2 = daytime('2025-12-31')
date1.isSameYear(date2)// trueisSameWeek()
Section titled “isSameWeek()”Check if dates are in the same week:
const date1 = daytime('2025-11-15')// Saturday
const date2 = daytime('2025-11-16')// Sunday
date1.isSameWeek(date2)// false (Saturday and Sunday may be in different weeks)
// Dates in the same weekconst monday = daytime('2025-11-17')const tuesday = daytime('2025-11-18')
monday.isSameWeek(tuesday)// true (same week)isSameQuarter()
Section titled “isSameQuarter()”Check if dates are in the same quarter:
const date1 = daytime('2025-01-15').startOf('quarter')const date2 = daytime('2025-03-31').startOf('quarter')
date1.isSameQuarter(date2)// true (both normalized to start of quarter 1)
// Alternative: compare quarter values directlydaytime('2025-01-15').quarter() === daytime('2025-03-31').quarter()// true (both are quarter 1)This Period Checks
Section titled “This Period Checks”isThisMonth()
Section titled “isThisMonth()”Check if date is in current month:
daytime().isThisMonth()// true
daytime('2025-11-15').isThisMonth()// depends on current monthisThisYear()
Section titled “isThisYear()”Check if date is in current year:
daytime().isThisYear()// true
daytime('2025-01-01').isThisYear()// depends on current yearisThisQuarter()
Section titled “isThisQuarter()”Check if date is in current quarter:
daytime().isThisQuarter()// trueisThisWeek()
Section titled “isThisWeek()”Check if date is in current week:
daytime().isThisWeek()// trueWeekend and Business Day Checks
Section titled “Weekend and Business Day Checks”isWeekend()
Section titled “isWeekend()”Check if date is weekend (Saturday or Sunday):
daytime('2025-11-15').isWeekend()// true (Saturday)
daytime('2025-11-16').isWeekend()// true (Sunday)
daytime('2025-11-17').isWeekend()// false (Monday)isBusinessDay()
Section titled “isBusinessDay()”Check if date is a business day (Monday-Friday):
daytime('2025-11-17').isBusinessDay()// true (Monday)
daytime('2025-11-15').isBusinessDay()// false (Saturday)
daytime('2025-11-16').isBusinessDay()// false (Sunday)Other Checks
Section titled “Other Checks”isValid()
Section titled “isValid()”Check if date is valid:
daytime('2025-11-15').isValid()// true
daytime(new Date('invalid')).isValid()// false
daytime(new Date('2025-13-45')).isValid()// falseisLeapYear()
Section titled “isLeapYear()”Check if date is in a leap year:
daytime('2024-01-01').isLeapYear()// true
daytime('2025-01-01').isLeapYear()// falseisDST()
Section titled “isDST()”Check if date is in daylight saving time:
daytime('2025-07-15').isDST()// depends on timezone
daytime('2025-01-15').isDST()// depends on timezoneisUTC()
Section titled “isUTC()”Check if date is in UTC timezone:
daytime().isUTC()// depends on current timezoneExamples
Section titled “Examples”Validate Date Range
Section titled “Validate Date Range”function isValidRange(date: Daytime, start: Daytime, end: Daytime): boolean { return date.isValid() && date.isBetween(start, end)}
// Check if date is between start and endconst date = daytime('2025-11-15')const start = daytime('2025-11-01')const end = daytime('2025-11-30')isValidRange(date, start, end)// trueCheck if Event is Upcoming
Section titled “Check if Event is Upcoming”function isUpcoming(eventDate: Daytime): boolean { return eventDate.isValid() && eventDate.isFuture()}
const event = daytime('2026-01-01')isUpcoming(event)// trueFilter Today’s Events
Section titled “Filter Today’s Events”const events = [ daytime('2025-11-15'), daytime('2025-11-16'), daytime().add(1, 'day')]
const todayEvents = events.filter(event => event.isToday())console.log(todayEvents.length)// 1 (only events matching today's date)