Hi Frank,
You can convert the hhmmss portion of your timestamp to a "seconds-after-midnight" format without using the function seconds-from-formatted-time via the simple
compute seconds = ss + 60 * (mm + 60 * hh)
so you're not dependent on 6.3 if that's a requirement, with a similar conversion back.
Otherwise you can do adjustment on separate date and time fields as your code illustrates, perhaps applying day adjustments directly to the integer-of-date instead of converting to seconds to do so (it's presumably faster if that's a major use case).
Also, if your timestamp is local time and you're adjusting days over daylight saving time transitions you'll be able to avoid at least some of the issues involved in the lost/added hour. It's not perfect, but may be adequate for your purposes.
Bernie
------------------------------
Bernie Rataj
Senior Software Developer
IBM Canada Ltd.
Markham ON Canada
https://www.ibm.com/marketplace/ibm-compilers------------------------------
Original Message:
Sent: Tue November 23, 2021 07:03 PM
From: Frank Swarbrick
Subject: date/time arithmetic in pure COBOL
OK, I think I have it. Don't love it, but...
So I ended up with the following:
compute seconds = seconds + (adjust-by * adj-period) divide seconds by 86400 giving day-adjust remainder seconds add day-adjust to date-as-int
I've attached the full example.
I guess it's worth noting, it works only with V6.3.
------------------------------
Frank Swarbrick
Original Message:
Sent: Tue November 23, 2021 05:58 PM
From: Frank Swarbrick
Subject: date/time arithmetic in pure COBOL
I am trying to determine if using only COBOL functions we can do "date/time" arithmetic. I can do it with the LE functions by using CEESECS to convert a timestamp into an LE "seconds" field, updating this field by adding minutes (number of minutes * 60), hours (number of hours * 3600), days (number of days * 86400), etc., and then converting back to a timestamp using CEEDATM.
For COBOL, however, there are two separate "unformatted" types. There is an "integer" representing a date, and a "seconds" field that represents the time. I'm not sure how to accomplish date arithmetic with two separate fields like this. Any thoughts?
------------------------------
Frank Swarbrick
------------------------------