date fields and methods Dates and times, from @now(), '2026-11-19'->to_date() or ->to_date().
A field is a plain fact about the value, read with a dot and no brackets: $value.name. A method takes arguments or does work, and is called with ->: $value->name(arguments), or with the value piped in: $value |> name(arguments).
Fields Field Type Description .daynumber The day of the month. .day_of_yearnumber The day of the year, 1 to 366. .days_in_monthnumber How many days the date's month has, 28 to 31. .hournumber The hour, 0 to 23. .is_futurebool True when the date is after now. Tests can fix now with @with_clock(). .is_pastbool True when the date is before now. Tests can fix now with @with_clock(). .is_todaybool True when the date falls on today's date. .is_weekendbool True when the date is a Saturday or a Sunday. .minutenumber The minute. .monthnumber The month, 1 to 12. .quarternumber The quarter of the year, 1 to 4. .secondnumber The second. .weeknumber The ISO 8601 week number, 1 to 53. Weeks start on Monday, and week 1 holds the year's first Thursday. .weekdaystring The day of the week, such as Monday. .yearnumber The year.
From KScript.Core # date ->add (years?: number , months?: number , weeks?: number , days?: number ) → date The date this many years, months, weeks and days later: ->add(months: 1, days: 2). Months and years keep the day of the month where they can (31 January plus a month is 28 or 29 February). For hours and minutes, add a duration: $date + 2h30m.
Arguments can be named: ->add(…, months: …, weeks: …).
Example
.kscript XML Copy
<echo>{ '2026-11-30'->to_date()->add(months: 3, days: 1)->format() }</echo>.kscript XML Copy
echo '2026-11-30'->to_date()->add(months: 3, days: 1)->format()# date ->date () → date The date at midnight.
Example
.kscript XML Copy
<echo>{ '2026-11-19 14:30'->to_date()->date()->format('yyyy-MM-dd HH:mm') }</echo>.kscript XML Copy
echo '2026-11-19 14:30'->to_date()->date()->format('yyyy-MM-dd HH:mm')# date ->end_of (unit: day|week|month|quarter|year , week_start?: monday|tuesday|wednesday|thursday|friday|saturday|sunday ) → date The last moment of the day, week, month, quarter or year the date is in: ->end_of(month) is 23:59:59 on its last day.
Parameter Takes unit required one of these words: day|week|month|quarter|year week_start optional one of these words: monday|tuesday|wednesday|thursday|friday|saturday|sunday
Arguments can be named: ->end_of(…, week_start: …).
Example
.kscript XML Copy
<echo>{ '2026-11-19 14:30'->to_date()->end_of(week, week_start: monday)->format('yyyy-MM-dd HH:mm') }</echo>.kscript XML Copy
echo '2026-11-19 14:30'->to_date()->end_of(week, week_start: monday)->format('yyyy-MM-dd HH:mm')# date ->format (pattern?: date_format ) → string Writes the date the way a date_format says: ->format(dd-MM-yyyy), ->format('d MMMM yyyy') or ->format('HH:mm'). yyyy-MM-dd by default.
Example
.kscript XML Copy
<echo>{ '2026-11-19 14:30'->to_date()->format('dddd d MMMM yyyy, HH:mm') }</echo>.kscript XML Copy
echo '2026-11-19 14:30'->to_date()->format('dddd d MMMM yyyy, HH:mm')# date ->is_same (other: date , unit?: day|week|month|quarter|year ) → bool True when both dates are in the same day (the default), week, month, quarter or year.
Parameter Takes other required date unit optional one of these words: day|week|month|quarter|year
Arguments can be named: ->is_same(…, unit: …).
Example
.kscript XML Copy
<echo>{ '2026-11-19 09:00'->to_date()->is_same('2026-11-30'->to_date(), month) }</echo>.kscript XML Copy
echo '2026-11-19 09:00'->to_date()->is_same('2026-11-30'->to_date(), month)The date in ISO 8601 format.
Example
.kscript XML Copy
<echo>{ '2026-11-19 14:30'->to_date()->iso() }</echo>.kscript XML Copy
echo '2026-11-19 14:30'->to_date()->iso()# date ->since (other: date , in: days|weeks|months|years ) → number The whole days, weeks, months or years from other to this date, negative when other is later. Months and years count the way a birthday does: @today()->since($born, in: years) is an age. For the exact time between two dates, subtract them: $finish - $start is a duration.
Parameter Takes other required date in required one of these words: days|weeks|months|years
Arguments can be named: ->since(…, in: …).
Example
.kscript XML Copy
<echo>{ '2026-11-19'->to_date()->since('1990-12-01'->to_date(), in: years) }</echo>.kscript XML Copy
echo '2026-11-19'->to_date()->since('1990-12-01'->to_date(), in: years)# date ->start_of (unit: day|week|month|quarter|year , week_start?: monday|tuesday|wednesday|thursday|friday|saturday|sunday ) → date The first moment of the day, week, month, quarter or year the date is in. A week starts on the locale's first day unless week_start: says otherwise.
Parameter Takes unit required one of these words: day|week|month|quarter|year week_start optional one of these words: monday|tuesday|wednesday|thursday|friday|saturday|sunday
Arguments can be named: ->start_of(…, week_start: …).
Example
.kscript XML Copy
<echo>{ '2026-11-19 14:30'->to_date()->start_of(month)->format('yyyy-MM-dd HH:mm') }</echo>.kscript XML Copy
echo '2026-11-19 14:30'->to_date()->start_of(month)->format('yyyy-MM-dd HH:mm')# date ->subtract (years?: number , months?: number , weeks?: number , days?: number ) → date The date this many years, months, weeks and days earlier: ->subtract(days: 7). For hours and minutes, take away a duration: $date - 30m.
Arguments can be named: ->subtract(…, months: …, weeks: …).
Example
.kscript XML Copy
<echo>{ '2026-11-19'->to_date()->subtract(weeks: 2)->format() }</echo>.kscript XML Copy
echo '2026-11-19'->to_date()->subtract(weeks: 2)->format()# date ->timestamp () → number Seconds since 1970-01-01 UTC.
Example
.kscript XML Copy
<echo>{ '2026-01-01'->to_date()->timestamp() > 0 }</echo>.kscript XML Copy
echo '2026-01-01'->to_date()->timestamp() > 0Methods from any