First Sunday of the Month

I want to create a natural program to know which will be the first Sunday of the month

05/03/23 Sunday

Does anyone have an example?

There is an edit mask for date, namely (EM=O).

If, as in your example, you have a variable #DATE which has day 1 of a date such as 05/01/2023.

Now you must know what setting you have for DTFORM. I have DTFORM set to U (USA) which means that an edit mask will return a โ€œ1โ€ for a Sunday and a 7 for a Saturday.

So if you get the EM=o for the first day of May it will be a 2 which is Monday. This means that the first Sunday will be the 7th of the month.

steve

1 Like

Hello Martins,

We have open-source Natural Code samples available for sharing and contributing.
You may find some similar code in their which can help you.
You could also share your code samples.

SoftwareAG/adabas-natural-code-samples: Natural Code Samples contributed by the Natural community for Natural developers to implement standard or specific programming pattern (github.com)

1 Like

Edit-mask for date

DTFORM=U

If first-of-month = Tuesday (3) and you want to have the date for Thursday (5),

then first-Thursday := first-of-month + 5 โ€“ 3

1 Like

Is the DTFORM in NATPARM?

   TITLE 'NATURAL 315 PARAMETER MODULE PR001CO'                           
   NTPRM FNR=250,                          DEFAULT FILE          X        
         DBID=250,                         DEFAULT DBID          X        
         BPSFI=ON,                         BUFFER POOL PESQUISA  X        
         DTFORM=E,                         DATE FORMAT DD/MM/YY  X        
         DC=',',                           DECIMAL CHARACTER     X

Yes.

You can display it from a Natural session.

DEFINE DATA LOCAL                   
1 #DATA (A253/4)   1 REDEFINE #DATA 
  2 FILLER 33X                      
  2 #DTFORM (A1)                    
END-DEFINE                          
CALLNAT 'USR1005N' #DATA (*)        
DISPLAY #DTFORM                     
END
1 Like

I needed a brief distraction.

DEFINE DATA LOCAL
1 #DATE (N6)       1 REDEFINE #DATE
  2 #MMYY (A6)
1 #DATE-A (A8)
1 #FIRST (D)
1 #DAY (A1)        1 REDEFINE #DAY
  2 #D (N1)
1 #SUNDAY (D)
1 #DATA (A253/4)   1 REDEFINE #DATA
  2 FILLER 33X
  2 #DTFORM (A1)
END-DEFINE
CALLNAT 'USR1005N' #DATA (*)
*
REPEAT
  INPUT 'Date (mmyyyy):' #DATE (SG=F AD=M)
  COMPRESS '01'
           #MMYY
      INTO #DATE-A LEAVING NO SPACE
  MOVE EDITED #DATE-A       TO #FIRST (EM=DDMMYYYY)
  MOVE EDITED #FIRST (EM=O) TO #DAY
  IF  #DTFORM = 'U'
    THEN
      IF  #DAY = '1'
        THEN
          ASSIGN #SUNDAY = #FIRST
        ELSE
          ASSIGN #SUNDAY = #FIRST + 7 - #D + 1
      END-IF
    ELSE
      IF  #DAY = '7'
        THEN
          ASSIGN #SUNDAY = #FIRST
        ELSE
          ASSIGN #SUNDAY = #FIRST + 7 - #D
      END-IF
  END-IF
  DISPLAY #FIRST  (EM=MM-DD-YYYY)
          #DAY
          #DTFORM
          #SUNDAY (EM=MM-DD-YYYY)
END-REPEAT
END
2 Likes

It worked, thanks Ralph Zbrog :clap: :clap: :clap: :clap:

Would you like to add it to our code samples project ?

1 Like

Thank you for the contributors, it is now available on our GitHub project:

adabas-natural-code-samples/First Sunday of the month at main ยท SoftwareAG/adabas-natural-code-samples (github.com)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.