Skip to content

Component Getters

Get individual components of a date and time values.

Get the year:

const date = daytime('2025-11-15T14:30:45')
date.year()
// 2025

Get the month (1-12):

const date = daytime('2025-11-15T14:30:45')
date.month()
// 11

Get the day of month (1-31):

const date = daytime('2025-11-15T14:30:45')
date.day()
// 15

Get the hour (0-23) in local timezone:

const date = daytime('2025-11-15T14:30:45')
date.hour()
// 14

Get the minute (0-59):

const date = daytime('2025-11-15T14:30:45')
date.minute()
// 30

Get the second (0-59):

const date = daytime('2025-11-15T14:30:45')
date.second()
// 45

Get the millisecond (0-999):

const date = daytime('2025-11-15T14:30:45.789')
date.millisecond()
// 789

These methods return calculated values based on the date:

Get the day of week (0-6, Sunday is 0):

const date = daytime('2025-11-15')
// Saturday
date.dayOfWeek()
// 6

Get the day of year (1-366):

const date = daytime('2025-01-15')
date.dayOfYear()
// 15
const date2 = daytime('2025-12-31')
date2.dayOfYear()
// 365

Get the quarter (1-4):

const date = daytime('2025-11-15')
// Q4
date.quarter()
// 4
const date2 = daytime('2025-04-15')
// Q2
date2.quarter()
// 2

Get the week number:

const date = daytime('2025-11-15')
date.week()
// 46

Get the week number within the month:

const date = daytime('2025-11-15')
date.weekOfMonth()
// 3

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')
// 46
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
// }
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 }