KScript docs
EN

Types and validation

Date formats

A date_format says how a date is written. It is checked when it is made, so a slip such as YYYY (years are yyyy) or DD (days are dd) fails where it is written, not as odd output later. ->format() on a date and ->to_date() on text take one, quoted or not:

<let name="uk" type="date_format" value="dd-MM-yyyy" />
<let name="day" value="'2026-11-22T16:30:00'->to_date()" />
<echo>{ $day->format($uk) } { $day->format(yyyy-MM-dd) } { $day->format('d MMMM yyyy, HH:mm') }</echo>
<echo>{ '22-11-2026'->to_date(dd-MM-yyyy)->format(dddd) } { $uk.example } { $uk.has_time }</echo>
$uk: date_format = dd-MM-yyyy
$day = '2026-11-22T16:30:00'->to_date()
echo "{ $day->format($uk) } { $day->format(yyyy-MM-dd) } { $day->format('d MMMM yyyy, HH:mm') }"
echo "{ '22-11-2026'->to_date(dd-MM-yyyy)->format(dddd) } { $uk.example } { $uk.has_time }"
Letters Mean
d, dd, ddd, dddd The day: 7, 07, Sat, Saturday
M, MM, MMM, MMMM The month: 3, 03, Mar, March
yy, yyyy The year: 26, 2026
H, HH, h, hh, tt The hour on a 24-hour clock, on a 12-hour clock, and AM or PM
m, mm, s, ss, fff Minutes, seconds and milliseconds
zzz, K The offset from UTC (+01:00) and the time zone (Z for UTC)

Anything else that is a letter goes in quotes, such as 'at' HH:mm, apart from T and Z, which stand for themselves in ISO 8601 (yyyy-MM-ddTHH:mm:ssZ). Spaces and punctuation are kept as written. A format of one letter is a standard .NET format: o is the round-trip ISO 8601 form, and d on its own is the short date. A format without quotes can't hold spaces or a : when it is an argument; write 'd MMMM yyyy' and 'HH:mm' there, or declare it first ($at: date_format = d MMMM yyyy, HH:mm).

.tokens lists its parts (['dd', '-', 'MM', '-', 'yyyy']), .example shows Saturday 7 March 2026 at 14:05:09 written that way, and ->parse(text) reads text written that way. The editor suggests the letters as you type a date format.