Component Getters
Get individual components of a date and time values.
Basic Components
Section titled “Basic Components”year()
Section titled “year()”Get the year:
const date = daytime('2025-11-15T14:30:45')date.year()// 2025month()
Section titled “month()”Get the month (1-12):
const date = daytime('2025-11-15T14:30:45')date.month()// 11Get the day of month (1-31):
const date = daytime('2025-11-15T14:30:45')date.day()// 15hour()
Section titled “hour()”Get the hour (0-23) in local timezone:
const date = daytime('2025-11-15T14:30:45')date.hour()// 14minute()
Section titled “minute()”Get the minute (0-59):
const date = daytime('2025-11-15T14:30:45')date.minute()// 30second()
Section titled “second()”Get the second (0-59):
const date = daytime('2025-11-15T14:30:45')date.second()// 45millisecond()
Section titled “millisecond()”Get the millisecond (0-999):
const date = daytime('2025-11-15T14:30:45.789')date.millisecond()// 789Derived Components
Section titled “Derived Components”These methods return calculated values based on the date:
dayOfWeek()
Section titled “dayOfWeek()”Get the day of week (0-6, Sunday is 0):
const date = daytime('2025-11-15')// Saturday
date.dayOfWeek()// 6dayOfYear()
Section titled “dayOfYear()”Get the day of year (1-366):
const date = daytime('2025-01-15')date.dayOfYear()// 15
const date2 = daytime('2025-12-31')date2.dayOfYear()// 365quarter()
Section titled “quarter()”Get the quarter (1-4):
const date = daytime('2025-11-15')// Q4
date.quarter()// 4
const date2 = daytime('2025-04-15')// Q2
date2.quarter()// 2week()
Section titled “week()”Get the week number:
const date = daytime('2025-11-15')date.week()// 46weekOfMonth()
Section titled “weekOfMonth()”Get the week number within the month:
const date = daytime('2025-11-15')date.weekOfMonth()// 3Generic Getter
Section titled “Generic Getter”Get any component by unit:
const date = daytime('2025-11-15T14:30:45')
date.get('year')// 2025
date.get('month')// 11
date.get('day')// 15
date.get('hour')// 14
date.get('minute')// 30
date.get('second')// 45
date.get('millisecond')// 0
date.get('quarter')// 4
date.get('week')// 46Examples
Section titled “Examples”Extract All Components
Section titled “Extract All Components”const date = daytime('2025-11-15T14:30:45.789')const components = { year: date.year(), month: date.month(), day: date.day(), hour: date.hour(), minute: date.minute(), second: date.second(), millisecond: date.millisecond(), dayOfWeek: date.dayOfWeek(), dayOfYear: date.dayOfYear(), quarter: date.quarter(), week: date.week()}
console.log(components)// {// year: 2025,// month: 11,// day: 15,// hour: 14,// minute: 30,// second: 45,// millisecond: 789,// dayOfWeek: 6,// dayOfYear: 319,// quarter: 4,// week: 46// }Check Quarter
Section titled “Check Quarter”function getQuarterInfo(date: Daytime) { return { quarter: date.quarter(), week: date.week(), weekOfMonth: date.weekOfMonth() }}
const info = getQuarterInfo(daytime('2025-11-15'))// { quarter: 4, week: 46, weekOfMonth: 3 }