Skip to main content

Calculating the day of the week in COBOL.

  • February 15, 2013
  • 0 replies
  • 3 views

Problem:

Sometimes there is a need to display the day of the week from a COBOL program.

Resolution:

The following code sample shows a way of calculating the day of the week from any given date.  The date needs to be in the format YYYYMMDD.

working-storage section.

01  ws-weekdays              pic x(21) value "SunMonTueWedThuFriSat".

01  ws-week-day              redefines ws-weekdays occurs 7 times.

01  ws-date                  pic 9(8) value 0.

01  ws-day                   pic 9(1) value 0.

        ...

     compute ws-day =

        (function mod(function integer-of-date(ws-date) 7)) 1

     end-compute.

     display ws-week-day(ws-day).

Where ws-day equals 1 forSunday, 2 for Monday and through to 7 for Saturday.

Old KB# 4385