Skip to main content

Dates, continued

The date functions are $ZDate (internal->external), and $ZDateH (external->internal). These functions have multiple arguments, which the Caché documentation describes. For this tutorial, you only need to understand the first (internal or external date to be converted), second (external format code), and ninth (error code to be returned) arguments.

The first example shows valid and invalid dates, and the success or failure of conversion by the $ZDateH function. Expressions using T (for today), and adding or subtracting days, are also valid. By default, $ZDateH generates an error for invalid dates, but its ninth argument allows you to specify an error code it should return instead.

SAMPLES>write $zdateh("9/21/1999", 5,,,,,,, -1)
57972
SAMPLES>write $zdateh("21/9/1999", 5,,,,,,, -1)
-1
SAMPLES>write $zdateh("21 SEP", 5,,,,,,, -1)
57972
SAMPLES>write $zdateh("SEP 21 1998", 5,,,,,,, -1)
57607
SAMPLES>write $zdateh("2 29 2000", 5,,,,,,, -1)
58133
SAMPLES>write $zdateh("2.29.1999", 5,,,,,,, -1)
-1
SAMPLES>write $zdateh("T+12", 5,,,,,,, -1)
57985
SAMPLES>write $zdateh("MAT 3", 5,,,,,,, -1)
-1
SAMPLES>

The second example shows $Horolog, and several formats of $ZDate.

SAMPLES>write $horolog
57973,50111
SAMPLES>write $zdate($horolog)
09/22/99
SAMPLES>write $zdate($horolog, 2)
22 Sep 99
SAMPLES>write $zdate($horolog, 3)
1999-09-22
SAMPLES>
FeedbackOpens in a new tab