Tivoli Service Desk 6.0 Developer's Toolkit Script Language Reference

Date and Time Manipulation

Return to Main Page


$Now

Description

A system-defined function that returns the current time.

Syntax

 FUNCTION $Now: TIME;

Example

 VARIABLES
 t: Time;
 ACTIONS
 t:=$Now;

$Today

Description

A system-defined function that returns the current date.

Syntax

 FUNCTION $Today: DATE;

Example

 VARIABLES
 d: Date;
 ACTIONS
 d:=$Today;

DateAdd

Description

Adds days, months, or years to a date.

Syntax

 FUNCTION DateAdd (VAL d: DATE, VAL n: INTEGER [,$DAYS|$MONTHS|$YEARS] ): DATE;

Argument Notes

Argument Name Description
d The date to which n units are to be added.
n The number to be added. This must be in one of the defined units.
$DAYS
$MONTHS
$YEARS
$DAYS, $MONTHS, $YEARS The units used to express n. If this argument is omitted, the default is $DAYS.

Notes

This function returns a date which is the n argument number of days, months, or years from the d argument date. If the n argument is positive, the result follows the given date. If the n argument is negative, the result precedes the given date.

Results are adjusted to yield valid dates. When the units parameter is $MONTHS, the result adjusts to allow for 28- and 30- day months.

When the units parameter is $YEARS, the result adjusts to allow for leap years. For example, if you to add one month to a base date of January 31, 1999, the result is March 3, 1999, not February 31, 1999.

Example

dueDate := DateAdd(billingDate, 30);

Return Codes

The result of the calculation is returned.

See Also


DateDif

Description

Calculates the difference between two dates.

Syntax

FUNCTION DateDif (VAL day1: DATE,
                  VAL day2: DATE [,$DAYS|$MONTHS|$YEARS]
                  ): INTEGER;

Argument Notes

Argument Name Description
day1 A date expression.
day2 A date expression.
$DAYS, $MONTHS, or $YEARS The units used to express the difference between dates. If this argument is omitted, the default is $DAYS.

Notes

DateDif calculates the difference between two dates by subtracting the day2 argument from the day1 argument and returns an integer result in days, months, or years.

Note: If the day2 argument is more recent than the day1 argument, a negative number is returned.

Example

VARIABLES
i: INTEGER;
ACTIONS
i:= DateDif ($Today,{1,1,1998}:
             DATE,$Days);
(* calculates how many days it is since 1/1/1998 *)

See Also

DateAdd


DateFormat

Description

Inspects or alters the default text format for date values.

Syntax

FUNCTION DateFormat [ ( VAL format: INTEGER ) ] : INTEGER;

Argument Notes

Argument Name Description
format If provided, this argument replaces the default format

Notes

This function is used to inspect and alter the default format when a date value is converted into a text form. If called with no argument, DateFormat returns the current default date format.

If an argument is provided, that value becomes the new default date format. DateFormat returns the old default date format.

Note: For a list of display format constants, see "DataType Format Flags."

Example

CONSTANTS
oracleDate IS $FmtDateYearMonthDay
 + $FmtDateTruncateCentury
 + $FmtDateDashSeparators
 + $FmtDateNamedMonth
 + $FmtDateShortNames
 + $FmtDateAllCaps
 + $FmtZeroPad;
VARIABLES
oldFormat: INTEGER;

ACTIONS
oldFormat := DateFormat
(oracleFormat);

...

DateFormat (oldFormat);
END;

See Also


TimeAdd

Description

Adds seconds, minutes, or hours to a time in the units you specify.

Syntax

FUNCTION TimeAdd (VAL t: TIME,
                  VAL n: INTEGER [, $SECONDS|$MINUTES|$HOURS]
                  ): TIME;

Argument Notes

Argument Name Description
t The original time.
n Amount of time to add. The choices are:
  • $SECONDS
  • $MINUTES
  • $HOURS

The default units in which the sum of t+n is returned is $SECONDS.

Return Codes

TimeAdd returns the new time in the units you specified.


TimeDif

Description

Returns the difference between two times in hours, minutes, or seconds.

Syntax

FUNCTION TimeDif (VAL t1, t2: TIME
                  [,$SECONDS|$MINUTES|$HOURS]
                  ):INTEGER;

Argument Notes

Argument Name Description
t1 A time expression.
t2 A time expression. The choices are:
  • $SECONDS
  • $MINUTES
  • $HOURS

The default for units in which the difference is to be returned is $SECONDS.

Notes

TimeDif calculates the difference between two time expressions and returns the difference. The second argument is subtracted from the first (time_1-time_2) and is expressed in hours, minutes, or seconds depending upon the system constant passed as the third argument.

When the third argument is $MINUTES or $HOURS, the result is truncated. Thus, the difference between {7,0,0}:TIME and {8,59,59}:TIME is 7199 seconds, or 119 minutes, or 1 hour.

Example

VARIABLES
 i: INTEGER;
ACTIONS
 i:=TimeDif($Now,{8,30,0}: TIME,$Minutes);
 (* i = number of minutes since 8:30 this morning *)
 i:=TimeDif ($Now, TimeAdd({8,30,0}:TIME, 30, $MINUTES),
$HOURS);
 (* i=number of hours since 8:30 this morning, rounded to *)
 (* the nearest hour *)

Return Codes

Return Code Description
any Time difference.

TimeFormat

Description

Inspects or alters the default text format for time values.

Syntax

FUNCTION TimeFormat [ ( VAL format: INTEGER ) ] : INTEGER;

Argument Notes

Argument Name Description
format If provided, this argument replaces the default.

Notes

TimeFormat inspects or alters the default format whenever a value of this type is converted into a text form.

If called with no argument, TimeFormat returns the existing default. If an argument is provided, that value becomes the new default. (The old default is returned.)

Example

VARIABLES
oldFormat: INTEGER;
ACTIONS
oldFormat :=
TimeFormat(BitOr($FmtTimeAMPM,
 $FmtTimeWithoutSeconds));

...

TimeFormat(oldFormat);
END;

See Also

For an explanation of display formats, see Data Type Format Flags.


Tivoli Service Desk 6.0 Developer's Toolkit Script Language Reference

Return to Main Page

Copyright