asgmt and asutc

These functions convert the contents of a variable to a date/time string formatted to the ISO 8601 date and time format, which is ddd, dd MMM yyyy HH:mm:ss. For example: “Mon, 03 Oct 2021 13:35:14”. The asgmt function converts time into GMT and the asutc function converts time into UTC.

When using these functions, the format of the time contained in the variable cannot include either:

  • An offset from UTC.
  • A Z character, such as 2021-03-04 18:54:39.000Z, which indicates that the time has zero offset from GMT/UTC.

Including either of these causes an error when asgmt or asutc attempts to convert time zones because the original time zone is seen as being different from the tenant's time zone. In addition, to avoid the error while using the ISO 8601 date-time format, include a Timezone action before the Snippet action and set it to use your tenant's time zone. This sets the time zone at the script level so the script and your tenant have the same time zone.

copy

Examples of asgmt and asutc

//IF TEST = 1
//{
  ASSIGN MyDateTime = #"{now}"
//}

//asgmt -- [String expression] Converts the contents of the variable to a 
//date/time string formatted to ISO 8601 format, which is:
// ddd, dd MMM yyyy HH:mm:ss gmt
//Example:  Mon, 03 Oct 2009 13:35:14 gmt 

//[Numeric expression] Converts the contents of the variable TO an OLE 
//automation date/time translated TO Coordinated Universal time (utc). 
//The variable must contain a valid string representation of a date/time. 
//The source time is based on the business unit time zone OR the time zone 
//set through the TIMEZONE script action.

ASSIGN GMTDateTimeNumeric = MyDateTime.asgmt
ASSIGN GMTDateTimeString = "{GMTDateTimeNumeric.asdatetime}"

//asutc -- The same as asgmt except in UTC.

ASSIGN UTCDateTimeNumeric = MyDateTime.asutc
ASSIGN UTCDateTimeString = "{UTCDateTimeNumeric.asdatetime}"

Download this snippet?