Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Introduction

Excerpt

If you are using these functions in conjunction with either the Now() or Now_() functions, be aware that the time zone returned is the one configured on the machine running the agent. All Cloud Agents are in UTC. Private Agents will vary based on the specific machine each agent is running on. If you are using a conversion function take this into account if your project is designed to run both in the cloud and on a Private Agent.

Time Zone Codes

The time zone parameters are one of the standard time zone codes, either a full name (TZ code) such as "America/Los_Angeles", a UTC offset such as "UTC-8:00", or an abbreviation such as "PST" (three-letter code). Time zone codes are case-sensitive. Full name TZ codes are recommended, if a time zone is being used, as "AST" can refer to either "Atlantic" or "Arabic" standard time.

Converting UNIX Times to dates

If a UNIX time is a number that includes millisecond precision, you can use code similar to this to convert a UNIX time to a date:

Code Block
// If you have a UNIX timestamp with milliseconds such as
createdate = "1478119530707";
// You can convert it to a date by 
// truncating the last three digits and using FormatDate:
date = double(Left(createdate, 10));
FormatDate(date, "yyyy-mm-dd");

ConvertTimeZone

Declaration

Code Block
string ConvertTimeZone(date d, string fromTZ, string toTZ[, bool is_european_format, bool ignoreDST])

string ConvertTimeZone(string d, string fromTZ, string toTZ[, bool is_european_format, bool ignoreDST])

Syntax

Code Block
ConvertTimeZone(<d>, <fromTZ>, <toTZ>[, <is_european_format>, <ignoreDST>])

Required Parameters

  • date: A date, either as a date object or as a date string
  • fromTZ: The time zone to be converted from, expressed as a time zone code
  • toTZ: The time zone to be converted to, expressed as a time zone code

Optional Parameters

  • is_european_format: This optional flag determines if the European date format is to be used. When true, the format is day and then month; when false, the format is month and then day.

  • ignoreDST: By default, daylight savings is accounted for when converting between the four major US time zones. Set this optional flag to true to override this action.

Description

Take a date and returns it converted from one time zone to another time zone.

Info

NOTE: If you are using ConvertTimeZone in conjunction with Now() or Now_(), be aware that the time zone returned is the one configured on the machine running the agent. All Cloud Agents are in UTC. Private Agents will vary based on the specific machine each agent is running on. If you are using a conversion function, such as ConvertTimeZone, take this into account if your project is designed to run both in the cloud and on a Private Agent.

Examples

Code Block
ConvertTimeZone(Now(), "UTC", "America/Los_Angeles", false, false);
// If Now() returns "2017-03-10 18:34:37"
// returns "2017-03-10 10:34:37" 

ConvertTimeZone("02/06/2017 5:25:00", "America/Los_Angeles", "America/New_York");
// Returns "2017-02-06 08:25:00" (shifts the time by 3 hours)

Backtotop

CVTDate

Declaration

Code Block
string CVTDate(date d, string inputFormat, string outputFormat)

string CVTDate(string d, string inputFormat, string outputFormat)

Syntax

Code Block
CVTDate(<d>, <inputFormat>, <outputFormat>)

Required Parameters

  • d: A date object or date string
  • inputFormat: A format string, specifying the format of the input date
  • outputFormat: format string, specifying the format of the output date

Description

Converts a date object or date string in the input format to a date string in the output format.

Info

NOTE: If you are using CVTDate in conjunction with Now() or Now_(), be aware that the time zone returned is the one configured on the machine running the agent. All Cloud Agents are in UTC. Private Agents will vary based on the specific machine each agent is running on. If you are using a conversion function, such as CVTDate, take this into account if your project is designed to run both in the cloud and on a Private Agent.

Examples

In these examples, it is assumed that all agents are running in the cloud, and times returned would be UTC. "myDate" is the  date June 19, 1994.

Formula

Input

Output

CVTDate(myDate, "mmddyy", "yyyymmdd")
06199419940619
CVTDate(myDate, "mmddyy", "ShortDate")
0619946/19/94
CVTDate(myDate, "mmddyy", "LongDate")
061994Sunday, June 19, 1994
CVTDate(Now(), "GeneralDate",
    "dd-mmm-yy, HH:MM AP")
on 1/31/17 at 12:39 PM in MST31-Jan-17, 07:39 PM
CVTDate(Now(), "GeneralDate",
    "dd-mmm-yy, HH:MM.SS AP")

on 1/31/17 at 12:39:13 PM in MST

31-Jan-17, 07:39:13 PM

CVTDate(Now_(), "GeneralDate",
    "ddmmmyyyy, HH:MM:SS.zzz AP")

on 1/31/17 at 12:39:13.310 PM in MST

31Jan2017, 07:39:13.310 PM

CVTDate(Now(), "GeneralDate",
    "yyyy_mm_dd_HH_MM")
on 1/31/17 at 12:39:13.310 PM in MST2017_01_31_19_39_13
CVTDate(Now(), "GeneralDateUTC",
"yyyy-mm-ddTHH:MM:SS.zzzZ")
on 1/31/17 at 12:39:13.310 PM in MST2017-01-31T0731T19:39:13.310Z
CVTDate(myDate, "mmddyy", "%Y%m%d%a")

061994

19940619Sun

CVTDate(myDate, "mmddyy", "%Y %m %d %a")

061994

1994 06 19 Sun

CVTDate(myDate, "mmddyy", "%Y %m %d %A")

061994

1994 06 19 Sunday

Format Strings

The format of both the input date string and the output date string are specified in the same way by using either characters for placeholders or one of the four predefined date formats (GeneralDate, LongDate, MediumDate, or ShortDate).

For inputs, the year, month, day, hour, minute, second, and AM/PM are read from the date string at the position where y, m, d, H, M, S, SSS, and AP appear in the input format string.

For outputs, the format string is copied to the data string with the year, month, day, hour, minute, and second replacing the characters of y, m, d, H, M, S, SSS, and AP.

Alternatively, the substitutions used in the ANSI C method strftime can be used. For example, the string "%Y-%m-%d" would result in the ISO 8601 date format (yyyy-mm-dd). See the external documentation on strftime  for a detailed description.

These codes can appear as required in the format string to specify how to read the input or to write the output:

Format

Input or Output

yyyy

4-digit year

yy

(last) 2-digit year

??yy

2- or 4-digit year

mmm

Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec

mm

2-digit month (01-12)

?m

1- or 2-digit month (1-12)

ddd

Julian date (001-366)

dd

2-digit day (01-31)

?d

1- or 2-digit day (1-31)

HH

Hour (00-23) or (01-12) if AM/PM is specified using AP

MM

Minute (00-59)

SS

Second (00-59)

zzzMillisecond (.001-.999)

AP

AM or PM

Anchor
format-strings-general-date
format-strings-general-date
GeneralDate

6/19/94 5:34:23 PM

Anchor
format-strings-long-date
format-strings-long-date
LongDate

Sunday, June 19, 1994

Anchor
format-strings-medium-date
format-strings-medium-date
MediumDate

19-Jun-1994

Anchor
format-strings-short-date
format-strings-short-date
ShortDate

6/19/94

Backtotop

DateAdd

Declaration

Code Block
string DateAdd(string datePart, int number, date d)

string DateAdd(string datePart, int number, string d)

Syntax

Code Block
DateAdd(<datePart>, <number>, <d>)

Required Parameters

  • datePart: A part code describing the part of the date to apply the addition to
  • number: An integer number to be added to the date part
  • d: The date object or a date string to be operated on

Description

Returns a date string after adding a number to a specified part of a date object.

These codes are used to describe the date parts:

Date Part

Part Code

Year

yyyy

Month

mm

Day

dd

Hour

hh

Minute

mi

Second

ss

Millisecondzzz

Examples

Code Block
DateAdd("yyyy", 1, Now());
// Adding one year to a date
// If Now() returns 2017-03-10 18:46:41
// returns "2018-03-10 18:46:41"

DateAdd("dd", 1, "2017-03-10");
// Adding one day to a date
// Returns "2017-03-11"

Backtotop

DayOfMonth

Declaration

Code Block
int DayOfMonth(date d)

int DayOfMonth(string d)

Syntax

Code Block
DayOfMonth(<d>)

Required Parameters

  • d: A date object or date string

Description

Returns the day of the month (1-31) of a date object or date string.

Examples

Code Block
DayOfMonth(Now());
// Returns 25 if today is December 25

Backtotop

DayOfWeek

Declaration

Code Block
int DayOfWeek(date d)

int DayOfWeek(string d)

Syntax

Code Block
DayOfWeek(<d>)

Required Parameters

  • d: A date object or date string

Description

Returns the day of the week for a date object or date string, with 0 for Sunday, 1 for Monday, on through 6 for Saturday.

This definition is independent of locale. For the weekday name, call FormatDate() instead.

Examples

Code Block
DayOfWeek(Now());
// Returns 0, if today is Sunday

Now() + (6 - DayOfWeek(Now()))*24*60*60;
// Returns the date object of the last day of the current week, 
// assuming Saturday (day 6) is the last day of the week

Backtotop

FormatDate

Declaration

Code Block
string FormatDate(date d, string format)

string FormatDate(string d, string format)

Syntax

Code Block
FormatDate(<d>, <format>)

Required Parameters

  • d: A date object or date string
  • format: A format string, specifying the format of the output date

Description

Converts a date object to a string according to a format string. This is similar to the CVTDate() function and uses the same format strings.

Examples

Code Block
FormatDate(Now(),"%w");
// Similar to DayOfWeek(Now()), except the return value 
// is a string value of today's weekday name, such as "Wed"

FormatDate("2017-12-07","%A");
// Returns the weekday name of the date string, such as "Thursday"

LPadChar(String(Long(FormatDate(d, "yyyy")) - 1900), "0", 3) + FormatDate(d, "ddd");
// Returns, for a date d, a string formatted as a JD Edwards Date ("CYYDDD")
// If d = "2000-12-31" (a leap year), returns "100366"
// See https://docs.oracle.com/cd/E26228_01/doc.93/e21961/julian_date_conv.htm#WEAWX259

Backtotop

GeneralDate

Declaration

Code Block
string GeneralDate(date d)

string GeneralDate(string d)

Syntax

Code Block
GeneralDate(<d>)

Required Parameters

  • d: A date object or date string

Description

Returns a string in the general date format for a date object or date string.

Examples

Code Block
GeneralDate(Now());
// If Now() is 11:59:23 am on September 16, 2000, 
// returns "09/16/2000 11:59:23 AM"

GeneralDate("2017-12-07");
// Returns "12/07/2017 12:00:00 AM"

Backtotop

GetUTCFormattedDate

Declaration

Code Block
string GetUTCFormattedDate(date d, string time_zone_id[, bool is_european_format])

string GetUTCFormattedDate(string d, string time_zone_id[, bool is_european_format])

Syntax

Code Block
GetUTCFormattedDate(<d>, <time_zone_id>[, <is_european_format>])

Required Parameters

  • d: A date object or date string
  • time_zone_id: The time zone to be converted from, expressed as a time zone code

Optional Parameters

  • is_european_format: This optional flag determines if the European date format is to be used. When true, the format is day and then month; when false, the format is month and then day.

Description

Returns a date string without time information. Converts a date object or date string to a string according to a time zone code.

Warning

WARNING: If passed a date with a time, the GetUTCFormattedDate() function truncates the time before converting to UTC. This means that timestamps that are after midnight UTC will be returned as occurring on the date before, as shown in the example above for the "America/Los_Angeles" time zone.

Info

NOTE: If you are using GetUTCFormattedDate in conjunction with Now() or Now_(), be aware that the time zone returned is the one configured on the machine running the agent. All Cloud Agents are in UTC. Private Agents will vary based on the specific machine each agent is running on. If you are using a conversion function, such as GetUTCFormattedDate, take this into account if your project is designed to run both in the cloud and on a Private Agent.

Examples

Code Block
// If Now() is 2017-12-09 18:46:41, then:

GetUTCFormattedDate(Now(), "UTC", false);
// Returns "2017-12-09"

GetUTCFormattedDate(Now(), "America/Los_Angeles", false); 
// Returns "2017-12-09"

Backtotop

GetUTCFormattedDateTime

Declaration

Code Block
string GetUTCFormattedDateTime(date d, string time_zone_id[, bool is_european_format])

string GetUTCFormattedDateTime(string d, string time_zone_id[, bool is_european_format])

Syntax

Code Block
GetUTCFormattedDateTime(<d>, <time_zone_id>[, <is_european_format>])

Required Parameters

  • d: A date object or date string
  • time_zone_id: The time zone to be converted from, expressed as a time zone code

Optional Parameters

  • is_european_format: This optional flag determines if the European date format is to be used. When true, the format is day and then month; when false, the format is month and then day.

Description

Returns a date string with time information. Converts a date object or date string to a string according to a time zone code.

Info

NOTE: If you are using GetUTCFormattedDateTime in conjunction with Now() or Now_(), be aware that the time zone returned is the one configured on the machine running the agent. All Cloud Agents are in UTC. Private Agents will vary based on the specific machine each agent is running on. If you are using a conversion function, such as GetUTCFormattedDateTime , take this into account if your project is designed to run both in the cloud and on a Private Agent.

Examples

Code Block
// If Now() is 2017-12-09 18:46:21, then:

GetUTCFormattedDateTime(Now(), "UTC", false);
// Returns "2017-12-09T18:46:21Z"

GetUTCFormattedDateTime(Now(), "America/Los_Angeles", false); 
// Returns "2017-12-10T02:46:21Z"

Backtotop

LastDayOfMonth

Declaration

Code Block
date LastDayOfMonth(date d)

date LastDayOfMonth(string d)

Syntax

Code Block
LastDayOfMonth(<d>)

Required Parameters

  • d: A date object or date string

Description

Returns a date object representing the last day of the month for a date object or date string.

Examples

Code Block
LastDayOfMonth(Now());
// If today is in February of a leap year,
// returns the date object of February 29

Backtotop

LongDate

Declaration

Code Block
string LongDate(date d)

string LongDate(string d)

Syntax

Code Block
LongDate(<d>)

Required Parameters

  • d: A date object or date string

Description

Returns a string in the long date format for a date object or date string.

Examples

Code Block
LongDate(Now());
// If Now() is 11:59:23 am on September 16, 2000,
// returns "Saturday, September 16, 2000"

Backtotop

LongTime

Declaration

Code Block
string LongTime(date d)

string LongTime(string d)

Syntax

Code Block
LongTime(<d>)

Required Parameters

  • d: A date object or date string

Description

Returns a string in the long time format for a date object or date string.

Examples

Code Block
LongTime(Now());
// If Now() is 11:59:23 am on September 16, 2000
// returns "11:59:23 AM"

Backtotop

MediumDate

Declaration

Code Block
string MediumDate(date d)

string MediumDate(string d)

Syntax

Code Block
MediumDate(<d>)

Required Parameters

  • d: A date object or date string

Description

Returns a string in the medium date format for a date object or date string.

Examples

Code Block
MediumDate(Now());
// If Now() is 11:59:23 am on September 16, 2000
// returns "16-Sep-00"

Backtotop

MediumTime

Declaration

Code Block
string MediumTime(date d)

string MediumTime(string d)

Syntax

Code Block
MediumTime(<d>)

Required Parameters

  • d: A date object or date string

Description

Returns a string in the medium time format for a date object or date string.

Examples

Code Block
MediumTime(Now());
// If Now() is 11:59:23 am on September 16, 2000
// returns "11:59 AM"

Backtotop

MonthOfYear

Declaration

Code Block
int MonthOfYear(date d)

int MonthOfYear(string d)

Syntax

Code Block
MonthOfYear(<d>)

Required Parameters

  • d: A date object or date string

Description

Returns the month (1-12) for a date object or date string.

Examples

Code Block
MonthOfYear(Now());
// If Now() is 11:59:23 am on September 16, 2000
// returns "9"

Backtotop

Now

Declaration

Code Block
date Now()

Syntax

Code Block
Now()

Description

Returns a date object representing the date and time values at the moment the function was run. The fraction of the second is truncated.

Info

NOTE: Be aware that the time zone of the date returned is the one configured on the machine running the agent. All Cloud Agents are in UTC. Private Agents will vary based on the specific machine each agent is running on. If you are using a conversion functions, take this into account if your project is designed to run both in the cloud and on a Private Agent.

Examples

Code Block
Now();
// If Now() is 11:59:23 am on September 16, 2000, 
// returns a date object representing 09/16/2000 11:59:23 AM

Backtotop

Now_

Declaration

Code Block
date Now_()

Syntax

Code Block
Now_()

Description

Returns a date object representing the date and time values at the moment the function was run. The time value includes the fraction of second (milliseconds).

Info

NOTE: Be aware that the time zone of the date returned is the one configured on the machine running the agent. All Cloud Agents are in UTC. Private Agents will vary based on the specific machine each agent is running on. If you are using a conversion functions, take this into account if your project is designed to run both in the cloud and on a Private Agent.

Examples

Code Block
Now_();
// If Now_() is 11:59:23.123 am on September 16, 2000 
// returns a date object representing 09/16/2000 11:59:23.123 AM

Backtotop

ShortDate

Declaration

Code Block
string ShortDate(date d)

string ShortDate(string d)

Syntax

Code Block
ShortDate(<d>)

Required Parameters

  • d: A date object or date string

Description

Returns a string in the short date format for a date object or date string.

Examples

Code Block
ShortDate(Now());
// If Now() is 11:59:23 am on September 16, 2017
// returns "9/16/17"

Backtotop

ShortTime

Declaration

Code Block
string ShortTime(date d)

string ShortTime(string d)

Syntax

Code Block
ShortTime(<d>)

Required Parameters

  • d: A date object or date string

Description

Returns a string in the short time format for a date object or date string.

Examples

Code Block
ShortTime(Now());
// If Now() is 11:59:23 am on September 16, 2017
// returns "11:59"

Backtotop

Panel
borderColor#65379B
titleColor#FFFFFF
titleBGColor#65379B
titleOn This Page
Table of Content Zone

Table of Contents
maxLevel2
minLevel2
indent20px
excludeSyntax|Declaration|Description|Example.*

Panel
borderColor#8C9CB4
titleColor#FFFFFF
titleBGColor#8C9CB4
titleSearch in This Topic
Page Tree Search
rootPageFunctions
Panel
borderColor#2076DA
titleColor#FFFFFF
titleBGColor#2076DA
titleRelated Functions
Multiexcerpt include
MultiExcerptNameconversion-functions-date
PageWithExcerptConversion Functions
Panel
borderColor#00B886
titleColor#FFFFFF
titleBGColor#00B886
titleRelated Topics

HideElements
metastrue

Last updated: 

Lastmodifieddate