Date and time
See this page for a general introduction to date and time handling in Numbat.
Defined in: datetime::functions, datetime::unixtime, datetime::human, datetime::julian_date
now
Returns the current date and time.
datetime
Parses a string (date and time) into a DateTime object. See here for an overview of the supported formats.
Example
datetime("2022-07-20 21:52 Europe/Berlin")
= 2022-07-20 21:52:00 CEST (UTC +02), Europe/Berlin [DateTime]
Example
Run this exampleformat_datetime
Formats a DateTime object as a string.
Example
format_datetime("This is a date in %B in the year %Y.", datetime("2022-07-20 21:52 +0200"))
= "This is a date in July in the year 2022." [String]
get_local_timezone
Returns the users local timezone.
tz
Returns a timezone conversion function, typically used with the conversion operator.
Example
datetime("2022-07-20 21:52 +0200") -> tz("Europe/Amsterdam")
= 2022-07-20 21:52:00 CEST (UTC +02), Europe/Amsterdam [DateTime]
Example
datetime("2022-07-20 21:52 +0200") -> tz("Asia/Taipei")
= 2022-07-21 03:52:00 CST (UTC +08), Asia/Taipei [DateTime]
today
Returns the current date at midnight (in the local time).
date
Parses a string (only date) into a DateTime object.
time
Parses a string (time only) into a DateTime object.
calendar_add
Adds the given time span to a DateTime. This uses leap-year and DST-aware calendar arithmetic with variable-length days, months, and years.
Example
calendar_add(datetime("2022-07-20 21:52 +0200"), 2 years)
= 2024-07-20 21:52:00 (UTC +02) [DateTime]
calendar_sub
Subtract the given time span from a DateTime. This uses leap-year and DST-aware calendar arithmetic with variable-length days, months, and years.
Example
calendar_sub(datetime("2022-07-20 21:52 +0200"), 3 years)
= 2019-07-20 21:52:00 (UTC +02) [DateTime]
weekday
Get the day of the week from a given DateTime.
unixtime
Converts a DateTime to a UNIX timestamp. Can be used on the right hand side of a conversion operator: now() -> unixtime.
Example
Run this exampleunixtime_s
Converts a DateTime to a UNIX timestamp in seconds.
unixtime_ms
Converts a DateTime to a UNIX timestamp in milliseconds.
Example
Run this exampleunixtime_µs
Converts a DateTime to a UNIX timestamp in microseconds.
Example
Run this exampleunixtime_us
Alias for unixtime_µs.
from_unixtime
Converts a UNIX timestamp to a DateTime object.
Example
Run this examplefrom_unixtime_s
Converts a UNIX timestamp in seconds to a DateTime object.
from_unixtime_ms
Converts a UNIX timestamp in milliseconds to a DateTime object.
from_unixtime_µs
Converts a UNIX timestamp in microseconds to a DateTime object.
from_unixtime_us
Alias for from_unixtime_µs.
human (Human-readable time duration)
Converts a time duration to a human-readable string in days, hours, minutes and seconds. More information here.
How long is a microcentury?
Run this examplejulian_date (Convert DateTime to Julian date)
Convert a DateTime to a Julian date, the number of days since the origin of the Julian date system (noon on November 24, 4714 BC in the proleptic Gregorian calendar).
More information here.
Example
Run this examplefrom_julian_date (Convert Julian date to DateTime)
Convert a Julian date to a DateTime.
More information here.
Example
Run this example