Skip to Content

Get the week number of the year for a date

Estimated Reading Time: 1 Minutes

One way to get the week number of a passed date is to use intrinsic functions.
Using several functions available in isCOBOL, you can get the Julian date, which will give you the date's number of days in the year.
Divide this by 7 and you'll have the week number.

For instance, December 25th is the 359th day of the year. The Julian date for December 25, 2023 is "2023225".
Using the fraction-part and integer-part functions, we can determine this is the 52nd week of the year

Compile and run the attached program with these commands:

   iscc week-of-year.cbl
   iscrun WEEK_OF_YEAR 
Your output will look like this for Christmas day, 2023:
   For date 20231225, The julian value is 2023359, and that date is in week # 52 of the year.
Other examples of using intrinsic functions to manipulate dates can be found in the sample programs installed in $ISCOBOL/sample/is-java/iscobol-uses-cobol-object/IS_DATE.
These programs validate a date, calculate the number of days between two dates, and return the day of the week.

Another way to work with dates is to use Java classes and OOP COBOL.
You can see an examples of this in KB article #119 here and in the sample program referenced above.

Get the week number of the year for a date
  • Attached Files
  • weekofyear.cbl (1.52 KB) 19