|
View previous topic :: View next topic
|
| Author |
Message |
andy12
New User
.jpg)
Joined: 30 Apr 2020 Posts: 18 Location: United States
|
|
|
|
FUNCTION ADD-DURATION is not used anymore in my shop. I need similar function or a way to code.
Here is my requirement, I'm getting the date and timestamp from
FUNCTION CURRENT-DATE TO WS-CURRENT-DATE-TIME
I want to add 30 seconds to it to make a new timestamp but i want my date, hour, min and seconds adjusted accordingly.
if 2024/02/29 - 23:59:59 is my current date and if i add 30 seconds to it. I want my new date as 2024/03/01 - 00:00:29
basically i want to handle all the overflow Seconds→minutes→hours→days→months→years, including leap year calculations
Thanks, |
|
| Back to top |
|
 |
Joerg.Findeisen
Senior Member

Joined: 15 Aug 2015 Posts: 1424 Location: Bamberg, Germany
|
|
|
|
| Have you searched the Forum for "FUNCTION ADD-DURATION" already? |
|
| Back to top |
|
 |
andy12
New User
.jpg)
Joined: 30 Apr 2020 Posts: 18 Location: United States
|
|
|
|
| Joerg.Findeisen wrote: |
| Have you searched the Forum for "FUNCTION ADD-DURATION" already? |
Yes I did |
|
| Back to top |
|
 |
Joerg.Findeisen
Senior Member

Joined: 15 Aug 2015 Posts: 1424 Location: Bamberg, Germany
|
|
|
|
| While working on something similar, I found it easier to work with seconds for the time issue. |
|
| Back to top |
|
 |
andy12
New User
.jpg)
Joined: 30 Apr 2020 Posts: 18 Location: United States
|
|
|
|
| Joerg.Findeisen wrote: |
| While working on something similar, I found it easier to work with seconds for the time issue. |
Do you have a solution to over come, if you could remember - please share some thoughts.. Thanks. |
|
| Back to top |
|
 |
PatrickDohman Currently Banned New User
Joined: 08 Oct 2025 Posts: 3 Location: United States
|
|
|
|
| andy12 wrote: |
ys→months→years, including leap year calculations
Thanks, |
Do you understand perform and varying?n Perhaps we are able to redefine??
| Code: |
[opc@instance-xxxxxxxx-1218 ~]$ /usr/bin/cat motto.cob
IDENTIFICATION DIVISION.
PROGRAM-ID. motto.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Computer.
05 WS-A PIC 9(4).
PROCEDURE DIVISION.
A-PARA.
PERFORM B-PARA VARYING WS-A FROM 1 BY 1 UNTIL WS-A=5
STOP RUN.
B-PARA.
DISPLAY 'GnuCOBOL REDEFINES ' WS-A.
|
| Code: |
[opc@instance-xxxxxxxx-1218 ~]$ ./motto
GnuCOBOL REDEFINES 0001
GnuCOBOL REDEFINES 0002
GnuCOBOL REDEFINES 0003
GnuCOBOL REDEFINES 0004
[opc@instance-20221211-1218 ~]$
|
|
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2263 Location: USA
|
|
|
|
| andy12 wrote: |
| basically i want to handle all the overflow Seconds→minutes→hours→days→months→years, including leap year calculations |
Take a look at these - Date Algorithms
I've implemented it in several projects, using both Assembler, and C++.
Now I'm lazy to do the same for COBOL, though this task is close to a piece of cake, when the algorithm is clearly explained.
P.S.
Compared to date calculation, the re-calculation of hours-minutes-seconds is "super piece of cake"; nothing to talk about. |
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2263 Location: USA
|
|
|
|
Another approach is using improved COBOL functions and operations to convert date/time between multiple formats.
Start from here: FORMATTED-DATETIME |
|
| Back to top |
|
 |
enrico-sorichetti
Superior Member

Joined: 14 Mar 2007 Posts: 10900 Location: italy
|
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2263 Location: USA
|
|
|
|
Re-inventing the wheel is nowaday's trend, especially in COBOL.
Out of several thousands of COBOL programs I was in touch with, about 95% do nothing else than reformatting and/or filtering records of input file(s).
All such programs can be easily replaced with DFSORT/SYNCSORT steps, with 10-100 times less source code, and 3-10 times better performance.
Still, in the current time COBOL developers continue their copy-paste activity on the code dated of 1965, with minor updates to generally the same code. |
|
| Back to top |
|
 |
PatrickDohman Currently Banned New User
Joined: 08 Oct 2025 Posts: 3 Location: United States
|
|
|
|
Does your program accept char and if so what are the supported encodings?
In the event you have a terminal that supports Hiragana for instance can we possibly determine the location of where the letter "A" is?
| Code: |
CONDITIONS.CBL
$ SET SOURCEFORMAT"FREE"
IDENTIFICATION DIVISION.
PROGRAM-ID. Conditions.
AUTHOR. Michael Coughlan.
*> An example program demonstrating the use of
*> condition names (level 88's).
*> The EVALUATE and PERFORM verbs are also used.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Char PIC X.
88 Vowel VALUE "a", "e", "i", "o", "u".
88 Consonant VALUE "b", "c", "d", "f", "g", "h"
"j" THRU "n", "p" THRU "t", "v" THRU "z".
88 Digit VALUE "0" THRU "9".
88 ValidCharacter VALUE "a" THRU "z", "0" THRU "9".
PROCEDURE DIVISION.
Begin.
DISPLAY "Enter lower case character or digit. No data ends.".
ACCEPT Char.
PERFORM UNTIL NOT ValidCharacter
EVALUATE TRUE
WHEN Vowel DISPLAY "The letter " Char " is a vowel."
WHEN Consonant DISPLAY "The letter " Char " is a consonant."
WHEN Digit DISPLAY Char " is a digit."
WHEN OTHER DISPLAY "problems found"
END-EVALUATE
END-PERFORM
STOP RUN.
|
Here we'll go ahead ask COBOL if the char あ is a vowel.
| Code: |
[opc@instance-xxxxxxxx-1218 ~]$ ./CONDITIONS
Enter lower case character or digit. No data ends.
あ
[opc@instance-xxxxxxxx-1218 ~]$
|
I suppose we'll need to refer to agent "N" aka the NATIONAL Field Definitions for the correct answer next time... |
|
| Back to top |
|
 |
Rohit Umarjikar
Global Moderator

Joined: 21 Sep 2010 Posts: 3109 Location: NYC,USA
|
|
|
|
How about function INTEGER-OF-DAYTIME?
Also if you have a db2 in your shop , you can easily do that using db2 function .
Lastly how about using DFSORT ? |
|
| Back to top |
|
 |
|
|