DateTime

7 functions for date and time manipulation. Useful for timestamping pipeline runs, parsing sample collection dates, and computing experiment durations.

now

Return the current date and time as a datetime object (UTC).

now() -> datetime
let start = now()
# ... run analysis ...
let elapsed = date_diff(start, now(), "seconds")
println("Analysis took", elapsed, "seconds")

timestamp

Return current Unix timestamp (seconds since epoch) as an integer.

timestamp() -> int
let ts = timestamp()   # 1709654400
let outfile = format("results_{}.csv", ts)   # "results_1709654400.csv"

date_format

Format a datetime as a string using strftime-style directives.

date_format(dt, format) -> string
DirectiveOutput
%Y4-digit year (2026)
%mMonth 01-12
%dDay 01-31
%H:%M:%STime (14:30:00)
%FISO date (2026-03-05)
let dt = now()
date_format(dt, "%Y-%m-%d")         # "2026-03-05"
date_format(dt, "%F %H:%M:%S")      # "2026-03-05 14:30:00"
date_format(dt, "run_%Y%m%d_%H%M")  # "run_20260305_1430"

date_parse

Parse a date string into a datetime object.

date_parse(s, format?) -> datetime
date_parse("2026-03-05")                    # ISO auto-detected
date_parse("05/03/2026", "%d/%m/%Y")         # explicit format
date_parse("March 5, 2026", "%B %d, %Y")    # natural format

# Parse sample collection dates
let dates = ["2025-01-15", "2025-02-20", "2025-03-10"]
let parsed = map(dates, |d| date_parse(d))

date_add

Add a duration to a datetime.

date_add(dt, amount, unit) -> datetime
UnitValues
"seconds", "minutes", "hours", "days", "weeks", "months", "years"Positive or negative integers
let collection_date = date_parse("2026-01-15")
let follow_up = date_add(collection_date, 90, "days")
println(date_format(follow_up, "%F"))   # "2026-04-15"

let deadline = date_add(now(), -7, "days")   # one week ago

date_diff

Compute the difference between two datetimes in the specified unit.

date_diff(a, b, unit) -> int
let start = date_parse("2025-06-01")
let end = date_parse("2026-03-05")
date_diff(start, end, "days")     # 277
date_diff(start, end, "months")   # 9

year / month / day / weekday

Extract components from a datetime.

year(dt) -> int
month(dt) -> int
day(dt) -> int
weekday(dt) -> int
let dt = date_parse("2026-03-05 14:30:00")
year(dt)      # 2026
month(dt)     # 3
day(dt)       # 5
weekday(dt)   # 4 (Thursday, 0=Monday)