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 could elect to do one operation on Friday and another on every other day.
Time services are provided by three functions which 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.
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. Note that the case matters. 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 |
z | Time zone | Text | EDT: The local time zone |
u | Unix Epoch time in seconds | Number | Must be only character in pattern |
U | Unix Epoch time in milliseconds | Number | Must be only character in pattern |
Except for special pattern characters such as u, the call must provide sufficient pattern characters to fill out the field for those in which length is specified. The following table provides a few examples:
cond(_now('E'),eqc,'Tue') | Do work on Tuesday only |
_now('hh:mm') | The current time, for example, 3:37, is expressed as 03:37. |
_now('D') | For July 21, 2006 day of year is 202 |
_now('dd/MM/yy') | European date 25/06/06 |
_now('z') | EDT |
_now('u') | 123594 |
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.
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.
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)
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. |
For example:
_fmtdate('yyyy.MM.dd', _dateof('MM/dd/yyyy','06/25/2009'))yields 2009.06.25.
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.
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/time in a format to be formatted based on the pattern. |
zone | literal | A timezone, such as Zulu. |
For example:
_dateof('MM/dd/yyyy', '06/25/2009') yields 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().
Let’s 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 |