Subject: | |
From: | |
Reply To: | |
Date: | Tue, 21 Apr 1998 19:34:20 GMT |
Content-Type: | text/plain |
Parts/Attachments: |
|
|
Glenn Cole ([log in to unmask]) wrote:
: All this time/hardware clock/software clock discussion is giving
: me a headache. Do you realize how many ways one can get the date
: in a COBOL program (most of which apply to other languages as well)?
: Let's give it a whirl:
: 1. CURRENT-DATE constant
: 2. CURRENT-DATE function (POST85)
: 3. CALENDAR intrinsic (not recommended ;)
: 4. HPCALENDAR intrinsic (5.5 pp4)
: 4. DATELINE intrinsic (can't manipulate results easily)
: 5. ALMANAC intrinsic (includes DOW, which is nice)
: Is there some "rule of thumb" that says when it is advisable
: to use each? I'll try a first pass:
I'll respond from a COBOL perspective:
: 1. CURRENT-DATE constant
: - COBOL standard
: - simplest to use
: - no allowance for multiple time zones
: - provides only 2-digit year
Not exactly a constant, it's what COBOL calls a special register.
It is not in the language standard, but is an extension supported
by a number of vendors, including HP. I don't recommend it.
: 2. CURRENT-DATE function
: - COBOL standard
: - more complex than CURRENT-DATE constant
: - supports multiple time zones (set TZ!)
: - provides 4-digit year
This is the way I recommend to get the current date in COBOL.
It is the only ANSI-standard method that provides a 4-digit
year. Yes, the TZ variable needs to be set correctly; consider
doing this in a system-wide logon UDC. And the system time
zone offset has to be right: check it with the SHOWCLOCK command,
change it with the CLKUTIL utility (safest) or the SETCLOCK command
(if you understand it).
: 3. CALENDAR intrinsic
: 4. HPCALENDAR intrinsic
: 5. DATELINE intrinsic
: 6. ALMANAC intrinsic
You didn't mention the ACCEPT statement (ACCEPT ... FROM DATE). It's
standard COBOL, but provides only a 2-digit year.
Walter Murray
Hewlett-Packard
Support Technology Lab
COBOL II/iX Project
|
|
|