How to find the Day of the week?

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.
Post Reply
Dino
Registered Member
Posts: 52
Joined: Tue Jun 18, 2013 12:12 am

How to find the Day of the week?

Post by Dino »

In COBOL, given an input date, how can I find the Day of week? What logic can be used. Please advise.
enrico-sorichetti
Global Moderator
Global Moderator
Posts: 825
Joined: Wed Sep 11, 2013 3:57 pm

Re: How to find the Day of the week?

Post by enrico-sorichetti »

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-)
Dino
Registered Member
Posts: 52
Joined: Tue Jun 18, 2013 12:12 am

Re: How to find the Day of the week?

Post by Dino »

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: 62
Joined: Wed Aug 07, 2013 6:43 pm

Re: How to find the Day of the week?

Post by dick scherrer »

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

Re: How to find the Day of the week?

Post by raazankeet »

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.
       

Dino
Registered Member
Posts: 52
Joined: Tue Jun 18, 2013 12:12 am

Re: How to find the Day of the week?

Post by Dino »

Thanks. This is working for me.
raazankeet
New Member
Posts: 5
Joined: Wed Jul 06, 2016 8:59 pm

Re: How to find the Day of the week?

Post by raazankeet »

Dino wrote: Thanks. This is working for me.
Good to hear that :)
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

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