datetime

now()

Returns the current date/time from the system UTC clock in ISO-8601 format.

Example

{
    currentZuluTime: ds.datetime.now()
}
Result:
{
    "currentZuluTime": "2019-08-19T18:58:38.313Z"
}

daysBetween(string datetime1, string datetime2)

Returns the number of days between datetime1 and datetime2. Dates are in "yyyy-MM-dd’T’HH:mm:ss.SSSVV" format.

Example

DataSonnet map:
local date1 = "2019-09-20T18:53:41.425Z";
local date2 = "2019-09-14T18:53:41.425Z";

ds.datetime.daysBetween(date1, date2)
Result
6

format(string datetime, string inputFormat, string outputFormat)

Reformats datetime using inputFormat and outputFormat.

Example

ds.datetime.format("2019-07-04T21:00:00Z", "yyyy-MM-dd'T'HH:mm:ssVV", "d MMM uuuu")
Result:
4 Jul 2019

isLeapYear(string datetime)

Returns a boolean indicating if datetime is a leap year. Dates are in "yyyy-MM-dd’T’HH:mm:ss.SSSVV" format.

Example

DataSonnet map:
ds.datetime.isLeapYear("2019-09-14T18:53:41.425Z")
Result
false

compare(string datetime1, string format1, string datetime2, string format2)

Returns 1 if datetime1 > datetime2, -1 if datetime1 < datetime2, and 0 if datetime1 == datetime2.

Example

ds.datetime.compare("2019-07-04T21:00:00-0500", "yyyy-MM-dd'T'HH:mm:ssZ", "2019-07-04T21:00:00-0500", "yyyy-MM-dd'T'HH:mm:ssZ")
Result
0

changeTimeZone(string datetime, string format, string timezone)

Changes the date timezone, retaining the instant. This normally results in a change to the local date-time. The response is formatted using the same format as an input.

Example

ds.datetime.changeTimeZone("2019-07-04T21:00:00-0500", "yyyy-MM-dd'T'HH:mm:ssZ", "America/Los_Angeles")
Result:
2019-07-04T19:00:00-0700

toLocalDate(string datetime, string format)

Returns only local date part of the datetime parameter in the ISO-8601 format without the offset.

Example

ds.datetime.toLocalDate("2019-07-04T21:00:00-0500", "yyyy-MM-dd'T'HH:mm:ssZ")
Result:
2019-07-04

toLocalTime(string datetime, string format)

Returns only local time part of the datetime parameter in the ISO-8601 format without the offset.

Example

ds.datetime.toLocalTime("2019-07-04T21:00:00-0500", "yyyy-MM-dd'T'HH:mm:ssZ")
Result:
21:00:00

toLocalDateTime(string datetime, string format)

Returns local datetime part of the datetime parameter in the ISO-8601 format without the offset.

Example

ds.datetime.toLocalDateTime("2019-07-04T21:00:00-0500", "yyyy-MM-dd'T'HH:mm:ssZ")
Result:
2019-07-04T21:00:00

offset(string datetime, string period)

Returns the local datetime part of the datetime parameter in the ISO-8601 format without the offset. The period is a string in the ISO-8601 period format.

Example

ds.datetime.offset("2019-07-22T21:00:00Z", "P1Y1D")
Result:
2020-07-23T21:00:00Z