IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

FUNCTION ADD-DURATION


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
andy12

New User


Joined: 30 Apr 2020
Posts: 18
Location: United States

PostPosted: Thu Sep 11, 2025 2:20 am
Reply with quote

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
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1424
Location: Bamberg, Germany

PostPosted: Thu Sep 11, 2025 10:59 am
Reply with quote

Have you searched the Forum for "FUNCTION ADD-DURATION" already?
Back to top
View user's profile Send private message
andy12

New User


Joined: 30 Apr 2020
Posts: 18
Location: United States

PostPosted: Thu Sep 11, 2025 6:10 pm
Reply with quote

Joerg.Findeisen wrote:
Have you searched the Forum for "FUNCTION ADD-DURATION" already?


Yes I did
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1424
Location: Bamberg, Germany

PostPosted: Thu Sep 11, 2025 7:15 pm
Reply with quote

While working on something similar, I found it easier to work with seconds for the time issue.
Back to top
View user's profile Send private message
andy12

New User


Joined: 30 Apr 2020
Posts: 18
Location: United States

PostPosted: Thu Sep 11, 2025 8:07 pm
Reply with quote

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
View user's profile Send private message
PatrickDohman
Currently Banned

New User


Joined: 08 Oct 2025
Posts: 3
Location: United States

PostPosted: Thu Oct 16, 2025 5:01 am
Reply with quote

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
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2263
Location: USA

PostPosted: Thu Oct 16, 2025 6:28 pm
Reply with quote

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
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2263
Location: USA

PostPosted: Thu Oct 16, 2025 6:52 pm
Reply with quote

Another approach is using improved COBOL functions and operations to convert date/time between multiple formats.

Start from here: FORMATTED-DATETIME
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10900
Location: italy

PostPosted: Thu Oct 16, 2025 9:35 pm
Reply with quote

why reinvent the wheel ... did anybody take in consideration
the LANGUAGE ENVIRONMENT date functions ( CEE***** )
www.ibm.com/docs/en/zos/2.5.0?topic=services-basics-using-date-time
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2263
Location: USA

PostPosted: Thu Oct 16, 2025 9:50 pm
Reply with quote

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
View user's profile Send private message
PatrickDohman
Currently Banned

New User


Joined: 08 Oct 2025
Posts: 3
Location: United States

PostPosted: Fri Oct 17, 2025 4:07 am
Reply with quote

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
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3109
Location: NYC,USA

PostPosted: Fri Oct 17, 2025 7:57 am
Reply with quote

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
View user's profile Send private message
View previous topic : : View next topic  
Post new topic   Reply to topic All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts COBOL 6.4 - User Defined Function nee... COBOL Programming 6
No new posts Calling an Open C library function in... CICS 1
No new posts DATE2 function SYNCSORT 15
No new posts Help on PL/I jsonPutValue function PL/I & Assembler 8
No new posts how to use Tso outtrap external function All Other Mainframe Topics 8
Search our Forums:


Back to Top