std.dato
std.dato works with calendar dates in a way that avoids the most common mistakes. A date is simply an integer — an ordinal counting days — so there is no time zone or clock to trip over.
std.dato works with calendar dates in a way that avoids the most common mistakes. A date is simply an integer — an ordinal counting days — and because there is no time zone or clock involved, you escape the errors that otherwise come from daylight saving and different zones.
The module converts between ordinals and year/month/day and ISO format, adds and subtracts days, months and years, compares two dates, and answers calendar questions such as weekday, week number, quarter and whether a day is a weekend. All expressed as ordinary arithmetic with integers.
When to use it
Use std.dato for anything to do with calendar dates: working out a due date, finding the next working day, counting days between two events, or displaying a date nicely. By using ordinals you avoid the errors that come from time zones and daylight saving.
Getting started
bruk std.dato som dato
funksjon start() -> heiltall {
la i_dag = dato.frå_ymd(2026, 8, 30)
la forfall = dato.pluss_dagar(i_dag, 14) // two weeks ahead
skriv(dato.til_iso(forfall)) // "2026-09-13"
skriv(dato.veekedag_namn(forfall))
returner 0
}Because dates are integers, "two weeks ahead" is just an addition. til_iso and veekedag_namn make the ordinal readable again.
The functions
Converting
Dates live as ordinals internally, but you want to read and write them as year/month/day or ISO text. These functions go both ways: frå_ymd and frå_iso in to an ordinal, til_ymd, til_iso and til_lang_format back out.
frå_ymd(år: heltall, månad: heltall, dag: heltall) -> heltall— Makes an ordinal from year, month and day.til_ymd(ordinal: heltall) -> liste_heltall— Turns an ordinal into[year, month, day].frå_ordinal(ordinal: heltall) -> liste_heltall— Turns an ordinal into[year, month, day].til_ordinal(år: heltall, månad: heltall, dag: heltall) -> heltall— Turns year, month and day into an ordinal (a day count).frå_iso(s: tekst) -> heltall— Interprets an ISO date (YYYY-MM-DD) and returns an ordinal.til_iso(ordinal: heltall) -> tekst— Formats an ordinal as an ISO date.til_lang_format(ordinal: heltall) -> tekst— Formats the date in a long, readable Norwegian format.
Calculating
Because a date is an integer, arithmetic is easy. Add or subtract days, months and years, count the days between two dates, or get the whole list of dates in an interval — with kvardagar_mellom including only the weekdays.
pluss_dagar(ordinal: heltall, dagar: heltall) -> heltall— Returns the date a given number of days later.minus_dagar(ordinal: heltall, dagar: heltall) -> heltall— Returns the date a given number of days earlier.pluss_månader(ordinal: heltall, månader: heltall) -> heltall— Returns the date a given number of months later.pluss_år(ordinal: heltall, år: heltall) -> heltall— Returns the date a given number of years later.dagar_mellom(frå: heltall, mål: heltall) -> heltall— Number of days between two dates.datoar_mellom(frå: heltall, mål: heltall) -> liste_heltall— A list of all the dates between two dates.kvardagar_mellom(frå: heltall, mål: heltall) -> liste_heltall— A list of only the weekdays between two dates.
Comparing
Three small functions to decide order: is a before, after or the same day as b.
er_før(a: heltall, b: heltall) -> bool— True ifais beforeb.er_etter(a: heltall, b: heltall) -> bool— True ifais afterb.er_lik_dato(a: heltall, b: heltall) -> bool— True if the two dates are the same day.
Calendar info
Everything you can ask the calendar: weekday and week number, whether it is a weekend, which quarter, day of the year, first and last day of the month, and whether the year is a leap year.
veekedag(ordinal: heltall) -> heltall— The weekday as a number.veekedag_namn(ordinal: heltall) -> tekst— The weekday's name.er_helg(ordinal: heltall) -> bool— True if the date falls on a Saturday or Sunday.er_kvardag(ordinal: heltall) -> bool— True if the date is a weekday.månadsnamn(månad: heltall) -> tekst— The name of the month.veeke_nummer(ordinal: heltall) -> heltall— The week number the date falls in.kvartal(ordinal: heltall) -> heltall— The quarter (1–4) the date falls in.dag_i_år(ordinal: heltall) -> heltall— Which day of the year the date is (1–366).første_i_månaden(ordinal: heltall) -> heltall— The ordinal for the first day of the same month.siste_i_månaden(ordinal: heltall) -> heltall— The ordinal for the last day of the same month.er_skotår(år: heltall) -> bool— True if the year is a leap year.dagar_i_år(år: heltall) -> heltall— Number of days in the year (365 or 366).dagar_i_månad(år: heltall, månad: heltall) -> heltall— Number of days in the given month.
Good to know
- An "ordinal" is just an integer counting days, so you can compare two dates with ordinary operators or
er_før/er_etter. - The module handles calendar dates, not clock times and time zones — which is exactly why you escape a whole class of bugs.
dagar_mellomanddatoar_mellomare useful for working out periods, for example the number of working days until a deadline.
std.dato is one of the modules in the standard library. Everything ships with the runtime — no installation, no external dependencies. See also Documentation for the language and the runtime.
Related
- std.tekststd.tekst is the toolbox for everything to do with text — searching and checking, splitting and joining, trimming whitespace, changing case, and converting to and from numbers.
- std.httpstd.http is a client for talking to other services over HTTP and HTTPS. You can fetch data, send data, and interpret the response — including JSON — without building the request by hand.
- std.dbstd.db gives you access to databases with a small, familiar set of functions: open a connection, run SQL, fetch values and rows, and control transactions.