Time Service Functions

In this section:

Time services are used to enter parameters requiring time of day operations or to test for values relating to the current time. For example, a process flow can be configured to perform one operation on Friday and another operation on every other day.

Time services are provided by three functions that all provide formatted access to the current time. This section lists and describes the various time service functions that you can use in iWay Service Manager.


Top of page

x
_now(): Get Current Timestamp

The _now() function returns the current time based on a provided pattern. It uses the following format:

_now([pattern])

pattern

string

Format pattern

The default pattern (MM/dd/yyyy) returns the date in month/day/year format. So, for example, the date might return as 06/15/2006 if the function _now() is entered with no pattern.

Pattern characters can be assembled to provide the desired return. The following table lists the characters and the expected result. Characters are case-sensitive. All examples are based on a time of June 15, 2006 at 13:02:08 PM.

Character

Use

Return type

Example

y

year

Digit

yyyy=2006, yy=06

M

Month of year

Depends on length

MM=06, MMM=Jun, MMMM=June

w

Week in year

Digit

26

W

Week in month

Digit

2

D

Day in year (Julian)

Digit

175

d

Day in month

Digit

25

E

Day of week

Text

Sun

F

Day of week in month

Digit

0

a

Division of day

Text

pm

H

Hour (24 hr clock, 0-23)

Digit

12

h

Hour (12 hr clock 1-12)

Digit

01

K

Hour (24 hr clock, 1-24)

Digit

13

k

Hour (12 hr clock, 0-11)

Digit

00

m

Minute in hour

Digit

02

s

Second in minute

Digit

08

S

Milliseconds

Digit

HH:mm:ss.SSS

z

Time zone

Text

EDT. The local time zone.

u

Unix Epoch time in seconds

Number

Must be the only character in the pattern.

U

Unix Epoch time in milliseconds

Number

Must be the only character in the pattern.

Un

Time in nanoseconds

Number

Must be the only character in the pattern. It is used to time events, but not as a clock.

Z

RFC-822 time zone

Number

-0500 (EST)

Except for special pattern characters, such as u, the function call must provide sufficient pattern characters to fill the field for those where length is specified. The following table provides a few examples:

cond(_now('E'),eqc,'Tue')

Does work on Tuesday only.

_now('hh:mm')

The current time. For example, 3:37 is expressed as 03:37.

_now('D')

For example, for July 21, 2006, the day of year is 202.

_now('dd/MM/yy')

European date format. For example:

25/06/06

_now('z')

EDT

_now('u')

123594

_now('Un')

94665599591459 as a timestamp

_now("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")

RFC 3339 (ISO 8601) time. For example:

2012-02-23T11:41:34.793Z

Note: Special characters can be included in the pattern by using an apostrophe. To avoid compiler confusion, surround the pattern string using double quotes.

The pattern Un represents the best time available for the system at the nanosecond level. This method can only be used to measure elapsed time and is not related to any other notion of system or wall-clock time. The value returned represents nanoseconds since some fixed but arbitrary. This method provides nanosecond precision, but not necessarily nanosecond accuracy. No guarantees are made about how frequently values change.



x
_tstamp(): Return the Current Time Stamp

The _tstamp() function returns a timestamp in ISO 8601 format. It uses the following format:

_tstamp()

This is a standard time function that is commonly used in many XML and web applications. The accuracy is to seconds. This function has no options.


Top of page

x
_ftstamp(): Return the Current Time Stamp to Milliseconds

The _ftstamp() function returns a time stamp to milliseconds in ISO 8601 format. It uses the following format:

_ftstamp(['compress'])

compress

literal

Format instruction

For example:

_ftstamp() yields 2006-07-21T19:42:44:609Z

The special pattern of the word compress eliminates the separator characters, yielding 20060721194244609Z. The compress option simplifies using the output in file names and in other situations in which the separator characters would be inappropriate.



x
_fmtdate(): Format a Date/Time from a Millisecond Time Value

The _fmtdate() function formats a date according to a pattern when a date is provided in milliseconds since January 1, 1970, 00:00:00 GMT. It uses the following format:

_fmtdate(pattern,value [,language, [,country]])

pattern

literal

A pattern as described for the _now() function. This pattern controls the formatting of the input value.

value

date/time

A date/time in a format to be formatted based on the pattern.

language

literal

The language code. By default, the language code is set according to the locale setting of the system where iSM is installed.

country

literal

The country code. By default, the country code is set according to the locale setting of the system where iSM is installed.

For example:

_fmtdate('yyyy.MM.dd', _dateof('MM/dd/yyyy','06/25/2009')) yields the following:

 2009.06.25

It is sometimes desirable to obtain the date for some moment in relation to the current moment. For example, you may want the current date/time for a date one week in the past:

_fmtdate('yyyy/MM/dd hh:mm:ss',_imul(_isub(_now(u),_imul(86400,7)),1000))

Replace the 7 in this example with the number of days desired. 86400 is the number of seconds in a day.

The language argument is a valid ISO Language Code. These codes are the lowercase, two-letter codes as defined by ISO-639. You can find a full list of these codes at a number of websites, such as http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt.

The country argument is a valid ISO Country Code. These codes are the upper case, two-letter codes as defined by ISO-3166. You can find a full list of these codes at a number of websites, such as http://www.iso.org/iso/country_codes.htm.

The language and country codes affect the language of the result, not the time zone offset specified by the pattern. The country code is required only in cases in which the language code is ambiguous.

For example, one hour from this moment:

_fmtdate('EEE, dd-MMM-yyyy HH:mm:ss zzz', _iadd(_now(),3600000), 'en') 

yields the following:

Wed, 31-Dec-2012 19:04:00 EST

For example:

_fmtdate('EEE, dd-MMM-yyyy HH:mm:ss zzz', _iadd(_now(),3600000), 'fr')

yields the following:

mer., 31-déc.-2012 19:04:00 EST

Note: Date operations can be performed by doing arithmetic on the values with appropriate patterns. The _now('U') function returns the current time for this function.


Top of page

x
_dateof(): Return the Time Stamp for a Passed Time

The _dateof() function parses a date and returns the corresponding number of milliseconds since January 1, 1970, 00:00:00 GMT. It uses the following format:

_dateof(pattern, value [,zone])

pattern

literal

A pattern as described for the _now() function. This pattern controls the formatting of the input value.

value

date/time

A date and time in a format to be formatted based on the pattern.

zone

literal

A time zone, such as Zulu.

For example:

_dateof('MM/dd/yyyy', '06/25/2009') yields the following:

 1245902400000

To create a duration suitable for date arithmetic, use the Zulu zone. This avoids any offset, so that a pattern, such as ss will give absolute seconds.

Note: The _iadd() and _isub() functions are preferred for date arithmetic because they operate on long integers with more precision than _add() and _sub().

Compute and display the time ten minutes ago. This example was run at 09/08/27 05:13:54.

_fmtdate('yy/MM/dd hh:mm:ss',_isub(_now(U),_dateof('mm',10,gmt)))

Results in 09/08/27 05:03:54.


iWay Software