How to find the Day of the week?

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.

Topic author
Dino
Registered Member
Posts: 31
Joined: Tue Jun 18, 2013 12:12 am
Has thanked: 1 time

How to find the Day of the week?

Postby Dino » Sat Mar 29, 2014 1:11 am

In COBOL, given an input date, how can I find the Day of week? What logic can be used. Please advise.



Online

enrico-sorichetti
Global Moderator
Global Moderator
Posts: 823
Joined: Wed Sep 11, 2013 3:57 pm
Been thanked: 69 times

Re: How to find the Day of the week?

Postby enrico-sorichetti » Sat Mar 29, 2014 2:16 am

the integer_of_date function returns an integer which has the peculiarity that
the remainder of the division by 7 ( modulus function )
gives the number of the day of the week 0-sunday .... 6-saturday


cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort 8-)


Topic author
Dino
Registered Member
Posts: 31
Joined: Tue Jun 18, 2013 12:12 am
Has thanked: 1 time

Re: How to find the Day of the week?

Postby Dino » Mon Apr 21, 2014 4:49 pm

Thanks Enrico.

IfI could a reference program it might just help me...though it's too much to ask...




dick scherrer
Former Team Member
Posts: 68
Joined: Wed Aug 07, 2013 6:43 pm
Been thanked: 1 time

Re: How to find the Day of the week?

Postby dick scherrer » Wed Apr 23, 2014 7:16 am

Hello,

Suggest you create a tiny test program to do this.

Post here when there are questions or problems.

You will learn more by doing and our goal is to help you learn.


Hope this helps,
d


raazankeet
New Member
Posts: 5
Joined: Wed Jul 06, 2016 8:59 pm
Been thanked: 1 time

Re: How to find the Day of the week?

Postby raazankeet » Sun Jul 09, 2017 6:26 pm

Going through old topics, this may help new members or someone very lazy :)

Code: Select all


       IDENTIFICATION DIVISION.
       PROGRAM-ID. YOUR-PROGRAM-NAME.
       DATA DIVISION.
       FILE SECTION.
       WORKING-STORAGE SECTION.
           01 WS-IN-DATE           PIC 9(8).
           01 WS-IN-DATE-FUNC      PIC 9(8).
           01 WS-DAY-OF-WEEK       PIC S9(08).
           01 WS-QUOTIENT          PIC S9(04).
           01 WS-REMAINDER         PIC S9(04).


       PROCEDURE DIVISION.
       MAIN-PROCEDURE.
           DISPLAY "Enter the date(YYYYMMDD):"
           ACCEPT WS-IN-DATE.
           DISPLAY "Entered date is: "WS-IN-DATE.
           COMPUTE WS-DAY-OF-WEEK = FUNCTION INTEGER-OF-DATE(WS-IN-DATE)
                 
               DIVIDE WS-DAY-OF-WEEK  BY 7 GIVING  WS-QUOTIENT 
                             REMAINDER WS-REMAINDER
               
               EVALUATE WS-REMAINDER
               when 0
                   DISPLAY WS-IN-DATE " is Sunday"
               when 1
                   DISPLAY WS-IN-DATE " is Monday"
               when 2
                   DISPLAY WS-IN-DATE " is Tuesday"
               when 3
                   DISPLAY WS-IN-DATE " is Wednesday"                   
               when 4
                   DISPLAY WS-IN-DATE " is Thursday"
               when 5
                   DISPLAY WS-IN-DATE " is Friday"
               when 6
                   DISPLAY WS-IN-DATE " is Saturday"
                   
               END-EVALUATE.

            STOP RUN.
       





Topic author
Dino
Registered Member
Posts: 31
Joined: Tue Jun 18, 2013 12:12 am
Has thanked: 1 time

Re: How to find the Day of the week?

Postby Dino » Mon Jul 10, 2017 4:08 pm

Thanks. This is working for me.




raazankeet
New Member
Posts: 5
Joined: Wed Jul 06, 2016 8:59 pm
Been thanked: 1 time

Re: How to find the Day of the week?

Postby raazankeet » Fri Jul 14, 2017 12:09 am

Dino wrote:Source of the post Thanks. This is working for me.

Good to hear that :)




Return to “IBM COBOL, GnuCOBOL (OpenCOBOL), OOCobol.”

Who is online

Users browsing this forum: CommonCrawl [Bot] and 0 guests