Skip to main content

Date Functions

The default date format is dates in UTC timezone in RFC3339 format.

Example:

now() ==> 2022-11-13T08:26:02Z

Date Arithmetic

To add and subtract time interval from another time use + and -

to_date("2022-11-13T08:26:02Z") + "3h"  ==> 2022-11-13T11:26:02Z
to_date("2022-11-13T08:26:02Z") - "5m" ==> 2022-11-13T08:21:02Z

Supported intervals:

    "s":  Second
"m": Minute
"h": Hour
note

Day, Month and Year are not supported because they have variable lengths.

Now | NowUnix | NowUnixMili

FunctionDescription
now()Returns the current time in timestamp format. Example output: 2022-07-28T15:02:26Z
now_unix()Returns the elapsed epoch current time. Example output: 1659020794
now_unix_mili()Returns the elapsed epoch milliseconds current time. Example output: 1659020794000
now() + "2h" ==> 2022-11-13T13:26:02Z

To Date

Use to_date to transform date string representation or date represented as Epoch time (seconds since 1970-01-01) into date. This enables performing date operations on the date such as +/-.

to_date("2022-11-13T08:26:02Z") + "3h"  ==> 2022-11-13T11:26:02Z
to_date(211863600) ==> 1976-09-18T03:00:00Z

To Epoch

Transforms the date string into Epoch time (seconds since 1970-01-01).
Also works with input which is already an Epoch, in which case it returns the input as is.

to_epoch("1976-09-18T03:00:00Z") ==> 211863600
to_epoch("211863600") ==> 211863600

To Epoch Mili

Transforms the date string into Epoch Milliseconds time (seconds since 1970-01-01).
Also works with input which is already an Epoch Milliseconds, in which case it returns the input as is.

to_epoch_mili("1976-09-18T03:00:00Z") ==> 211863600000
to_epoch_mili("211863600000") ==> 211863600000

To Local Time

Format the date as local time in a given time zone. Accepts dates as Epoch time or string in RFC3339 format.

to_local_time("2020-01-31T18:09:41Z", "UTC")
==> 2020-01-31T18:09:41Z
to_local_time("2020-01-31T18:09:41Z", "Europe/Berlin")
==> 2020-01-31T19:09:41+01:00
to_local_time("2020-01-31T18:09:41Z", "America/New_York")
==> 2020-01-31T13:09:41-05:00

Date Format

Format the date in user requested format. Inputs are:

  1. Layout in Golang date format convention.
  2. Input date in RFC3339 format or as an Epoch time (seconds since 1970-01-01).
date_format("2006-01-02T15:04:05.000Z", "2022-07-07T15:14:12Z")
==> 2022-07-07T15:14:12.000Z
date_format("2006-01-02", "2022-07-07T15:14:12Z")
==> 2022-07-07
date_format("2006-01-02", "2022-07-07T15:14:12Z") + "24h"
==> 2022-07-08