Page 1 of 1

How to find the Day of the week?

Posted: Sat Mar 29, 2014 1:11 am
by Dino
In COBOL, given an input date, how can I find the Day of week? What logic can be used. Please advise.

Re: How to find the Day of the week?

Posted: Sat Mar 29, 2014 2:16 am
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

Re: How to find the Day of the week?

Posted: Mon Apr 21, 2014 4:49 pm
by Dino
Thanks Enrico.

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

Re: How to find the Day of the week?

Posted: Wed Apr 23, 2014 7:16 am
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.

Re: How to find the Day of the week?

Posted: Sun Jul 09, 2017 6:26 pm
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.
       


Re: How to find the Day of the week?

Posted: Mon Jul 10, 2017 4:08 pm
by Dino
Thanks. This is working for me.

Re: How to find the Day of the week?

Posted: Fri Jul 14, 2017 12:09 am
by raazankeet
Dino wrote: Thanks. This is working for me.
Good to hear that :)