Current_time

This function gets the current time in UTC as a datetime object and adds &offset hours to it.

Syntax

datetime current_time(number|string $offset)

Gets current time in UTC and adds $offset value in hours.

Parameters

$offset: Amount of hours to add to current time.
$offset can be a string '0', or a number `0`.
If $offset is a string, it must have integer format, i.e. must be a whole number.
If $offset is a number, it can be a double, i.e. hold decimals. However, the value will be converted to an integer. `0.5` rounds down.
There is no limit for $offset.
Negative sign can be prefixed to $offset i.e. `-1`.

Example

{
    //No sample data needed
}
{
    UTC: current_time(`0`),
    UTCstring: current_time('0'),
    UTCplus1: current_time(`1`),
    UTCminus1: current_time(`-1`),
    UTCplus25: current_time(`25`)
}
{
    "UTC": "2022-11-10T12:51:49.4499414Z",
    "UTCstring": "2022-11-10T12:51:49.4499547Z",
    "UTCplus1": "2022-11-10T13:51:49.4499626Z",
    "UTCminus1": "2022-11-10T11:51:49.4499669Z",
    "UTCplus25": "2022-11-11T13:51:49.4499722Z"
}

This example showcases a variety of configuration options. No sample data is needed as UTC time is used as the data. Notice how “UTCplus25” adds a full day and one hour to the current time.

Notes

Synergy with format()

Before inserting datetime objects into a document, they likely need to be formatted. The format function can be used to format the datetime object to a string value, like this:

{
    UTC: current_time(`0`),
    FormattedDate: format($.UTC, 'dd.MM.yyyy', 'en-US')
}
{
    "UTC": "2022-11-10T13:41:37.1224697Z",
    "FormattedDate": "10.11.2022"
}

In above example, current datetime is defined as key “UTC”, and formatted using format() as key “FormattedDate”.