# First Sunday of the Month

**URL:** <https://techcommunity.softwareag.com/t/first-sunday-of-the-month/275229>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural\
**Created:** [February 27, 2023, 12:41pm UTC](https://techcommunity.softwareag.com/t/first-sunday-of-the-month/275229 "2023-02-27T12:41:17Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Claudemar\_Martins1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/claudemar_martins1/32/23394_2.png) [@Claudemar\_Martins1](https://techcommunity.softwareag.com/u/Claudemar_Martins1)\
**Post date:** [February 27, 2023, 12:41pm UTC](https://techcommunity.softwareag.com/t/first-sunday-of-the-month/275229/1 "2023-02-27T12:41:17Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [February 27, 2023, 1:16pm UTC](https://techcommunity.softwareag.com/t/first-sunday-of-the-month/275229/2 "2023-02-27T13:16:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Eli\_Cohen1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/eli_cohen1/32/39733_2.png) [@Eli\_Cohen1](https://techcommunity.softwareag.com/u/Eli_Cohen1)\
**Post date:** [February 27, 2023, 1:17pm UTC](https://techcommunity.softwareag.com/t/first-sunday-of-the-month/275229/3 "2023-02-27T13:17:48Z")

</div>

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)](https://github.com/SoftwareAG/adabas-natural-code-samples)

---

<div class="post-metadata">

**Author:** ![Dion\_Kejlberg](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/dion_kejlberg/32/525_2.png) [@Dion\_Kejlberg](https://techcommunity.softwareag.com/u/Dion_Kejlberg)\
**Post date:** [February 27, 2023, 1:18pm UTC](https://techcommunity.softwareag.com/t/first-sunday-of-the-month/275229/4 "2023-02-27T13:18:11Z")

</div>

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

![](https://global.discourse-cdn.com/techcommunity/original/3X/0/6/0666dde411bf2d4f1484559f8aa8ae4920b5d7f5.png)

---

<div class="post-metadata">

**Author:** ![Claudemar\_Martins1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/claudemar_martins1/32/23394_2.png) [@Claudemar\_Martins1](https://techcommunity.softwareag.com/u/Claudemar_Martins1)\
**Post date:** [February 27, 2023, 7:42pm UTC](https://techcommunity.softwareag.com/t/first-sunday-of-the-month/275229/5 "2023-02-27T19:42:49Z")

</div>

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
> 
> ```

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [February 27, 2023, 7:58pm UTC](https://techcommunity.softwareag.com/t/first-sunday-of-the-month/275229/6 "2023-02-27T19:58:36Z")

</div>

Yes.

You can display it from a Natural session.

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

```

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [February 27, 2023, 10:10pm UTC](https://techcommunity.softwareag.com/t/first-sunday-of-the-month/275229/7 "2023-02-27T22:10:04Z")

</div>

I needed a brief distraction.

```auto
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

```

---

<div class="post-metadata">

**Author:** ![Claudemar\_Martins1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/claudemar_martins1/32/23394_2.png) [@Claudemar\_Martins1](https://techcommunity.softwareag.com/u/Claudemar_Martins1)\
**Post date:** [February 27, 2023, 11:48pm UTC](https://techcommunity.softwareag.com/t/first-sunday-of-the-month/275229/8 "2023-02-27T23:48:13Z")

</div>

It worked, thanks Ralph Zbrog 👏 👏 👏 👏

---

<div class="post-metadata">

**Author:** ![Eli\_Cohen1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/eli_cohen1/32/39733_2.png) [@Eli\_Cohen1](https://techcommunity.softwareag.com/u/Eli_Cohen1)\
**Post date:** [February 28, 2023, 6:53am UTC](https://techcommunity.softwareag.com/t/first-sunday-of-the-month/275229/9 "2023-02-28T06:53:41Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![Eli\_Cohen1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/eli_cohen1/32/39733_2.png) [@Eli\_Cohen1](https://techcommunity.softwareag.com/u/Eli_Cohen1)\
**Post date:** [March 2, 2023, 8:04am UTC](https://techcommunity.softwareag.com/t/first-sunday-of-the-month/275229/10 "2023-03-02T08:04:06Z")

</div>

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)](https://github.com/SoftwareAG/adabas-natural-code-samples/tree/main/First%20Sunday%20of%20the%20month)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [August 29, 2023, 8:04am UTC](https://techcommunity.softwareag.com/t/first-sunday-of-the-month/275229/11 "2023-08-29T08:04:57Z")

</div>

Closed on August 29, 2023, 8:04am UTC

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