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 fractionpart and integerpart functions, we can determine this is the 52nd week of the year
Compile and run the attached program with these commands:
iscc weekofyear.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/isjava/iscobolusescobolobject/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.
