Jump to page titleUNITED STATES
hp.com home products and services support and drivers solutions how to buy
» contact hp

:

more options
 

hp.com home
End of Jump to page title
Example-PLI Adding and Subtracting Delta Times For Figuring Dates
Jump to content



» 

business support center

Home & Home Office Support:
» HP branded products
» Presario branded products
» Services & Warranties
Small & Medium Business Support:
» Small & Medium Business products
» Small & Medium Business services
Support for IT Professionals:
» Enterprise products (IT Resource Center)
» NonStop enterprise products
» Business & IT Services
Content starts here
Copyright (c) Digital Equipment Corporation 1988. All rights reserved
LAYERED PRODUCT: VAX PL1                        OP/SYS: VMS


SOURCE:     Digital Customer Support Center


OVERVIEW:

This program demonstrates how to reference a date/time in the past
or the future by adding or subtracting a delta date/time to an
absolute date/time.


CAUTION:  This sample program has been tested using VAX PL1 on VMS
V5.0. However, we cannot guarantee its effectiveness because of the
possibility of errors in transmitting or implementing it.  It is meant
to be used as a template for writing your own program, and it may
require modification for use on your system.


PROGRAM NOTES:

This progam inputs a date/time in absolute form from sys$input.  It
also inputs a date/time in delta format from sys$input.  It then calls
the system service SYS$BINTIM to convert these times to binary format.
To subtract the delta date/time from the absolute date/time, LIB$ADDX
is used.  To add the delta date/time to the absolute date/time, LIB$SUBX
is used.  Reverse functions are used since the arithmetic operation
uses the 2's compliment.  The resultant time is then passed to the
system service SYS$ASCTIM so that it may be printed to SYS$OUTPUT.

LIB$SUB_TIMES and LIB$ADD_TIMES would also perform this calculation,
but is new to 5.0 and does not require using the 2's compliment.


PROGRAM SAMPLE:

BINMAINC: proc options(main);

%include SYS$BINTIM;
%include SYS$ASCTIM;
%include LIB$SUBX;
%include LIB$ADDX;
%include $ssdef;
%include $stsdef;

dcl ascii_abs_time char(23);
dcl ascii_del_time char(16);
dcl result_time    char(23);
dcl diff_time    bit(64) aligned;
dcl binary_timed bit(64) aligned;
dcl binary_timea bit(64) aligned;
dcl blanks char(100) init(' ');
dcl answer char(1) init('S');
/*
    NOTE: All digits of date time do not need to be entered.  What is needed
    are the "placeholders" (i.e. the "-" and the ":").  For example:

   "10-JAN-" is sufficient for absolute time input.
        Current year and time will be used.  If no time is needed, no colons
        are needed.

   "5 12" could be used for delta time of 5 days and 12 hours.
        Leading zeros are not needed.
*/
put skip(2) list('Note that the MONTH (MMM) must be entered in upper case.');
put skip(2) list('Do you wish to [A]dd or [S]ubtract dates/times? ');
get edit (answer) (a(1));

put skip(2) list('Enter the absolute date/time in ASCII format');
put skip edit('DD-MMM-YYYY HH:MM:SS.CC',blanks) (a(23),a(57));
get edit(ASCII_ABS_TIME) (a(23));

put skip(2) list('Enter the delta date/time in ASCII format');
put skip edit('DDDD HH:MM:SS.CC',blanks) (a(16),a(64));
get skip edit(ASCII_DEL_TIME) (a(16));

sts$value = SYS$BINTIM(ascii_abs_time,binary_timea);
if ^sts$success then signal vaxcondition(sts$value);

sts$value = SYS$BINTIM(ascii_del_time,binary_timed);
if ^sts$success then signal vaxcondition(sts$value);

/* in order to subtract times and dates, use LIB$ADDX
   in order to add times and dates , use LIB$SUBX */

if answer = 'A' | answer = 'a'
        then sts$value = LIB$SUBX(binary_timea,binary_timed,diff_time,2);
        else sts$value = LIB$ADDX(binary_timea,binary_timed,diff_time,2);
        if ^sts$success then signal vaxcondition(sts$value);

sts$value = sys$asctim(,result_time,diff_time,);
if ^sts$success then signal vaxcondition(sts$value);

put file(sysprint) list ('Time difference =', result_time);

end binmainc;




buy online or call 1.800.AT.COMPAQ
privacy statementusing this site means you accept its terms