ESC
Type to search...
S
Soli Docs

DateTime Functions

Date/time parsing, formatting, arithmetic, and comparison using Unix timestamps.

Soli uses Unix timestamps (integers) for datetime operations. These are low-level functions prefixed with __datetime_. For higher-level operations, use the DateTime class.

Current Time

__datetime_now_local()

Get the current local time as a Unix timestamp.

Returns

Int - Unix timestamp in seconds
__datetime_now_utc()

Get the current UTC time as a Unix timestamp.

Returns

Int - Unix timestamp in seconds (UTC)

Parsing & Formatting

__datetime_parse(string)

Parse an ISO 8601 or RFC date string to a Unix timestamp.

let ts = __datetime_parse("2024-01-15T10:30:00Z")
let ts2 = __datetime_parse("2024-01-15")
__datetime_format(timestamp, format)

Format a timestamp using strftime format specifiers.

Common Format Specifiers

%Y - Year (4 digits)
%m - Month (01-12)
%d - Day (01-31)
%H - Hour (00-23)
%M - Minute (00-59)
%S - Second (00-59)
%B - Month name
%A - Weekday name
__datetime_format(ts, "%Y-%m-%d %H:%M:%S")  // "2024-01-15 10:30:00"
__datetime_format(ts, "%B %d, %Y")           // "January 15, 2024"
__datetime_format(ts, "%A")                  // "Monday"
__datetime_to_iso(timestamp)

Convert a timestamp to ISO 8601 format.

__datetime_to_iso(ts)  // "2024-01-15T10:30:00Z"

Date Components

__datetime_components(timestamp)

Get individual date/time components from a timestamp.

Returns

Hash with keys: year, month, day, hour, minute, second, weekday
let parts = __datetime_components(ts)
println(parts["year"])     // 2024
println(parts["month"])    // 1
println(parts["day"])      // 15
println(parts["weekday"])  // "monday"

Arithmetic & Comparison

__datetime_add(timestamp, seconds)

Add seconds to a timestamp.

let tomorrow = __datetime_add(ts, 86400)      // Add 1 day
let next_hour = __datetime_add(ts, 3600)      // Add 1 hour
__datetime_sub(timestamp, seconds)

Subtract seconds from a timestamp.

let yesterday = __datetime_sub(ts, 86400)  // Subtract 1 day
__datetime_diff(timestamp1, timestamp2)

Get the difference between two timestamps in seconds.

__datetime_is_before(ts1, ts2)

Check if ts1 is before ts2

__datetime_is_after(ts1, ts2)

Check if ts1 is after ts2