TypeCobolFunctionsExamples - TypeCobolTeam/TypeCobol GitHub Wiki

**TODO **

Examples of functions and procedures related to Date manipulation

ID DIVISION.
PROGRAM-ID. DVZZDATE.

data division.
working-storage section.
   01 DateJulian  TYPEDEF STRONG.
         10 YYYY PIC 9(04).
         10 DDD  PIC 9(03).     
       01 DateDB2 TYPEDEF STRONG.
         10  YYYY PIC 9(04).
         10  filler-X PIC X.
         10  MM PIC 9(02).
         10  filler-X PIC X.
         10  DD PIC 9(02).

PROCEDURE DIVISION.


declare function currentDate PRIVATE
returning result type Date.

data division.
procedure division.
    accept result from DATE YYYYMMDD.
end-declare.

declare function currentDateDB2 private
    returning result type DateDB2.

procedure division.
end-declare.

declare function currentDateJulian private.
    returning result type DateJulian.

procedure division.
end-declare.

declare function currentDateFreeFormat private.
    input     dateType      pic X
              direction     pic X
			    88 direction-YearFirst      value 'A'.
			    88 direction-DayFirst       value 'J'.
			    88 direction-MonthFirst     value 'M'.
			    88 direction-LocalDependent value 'L'.
              separator     pic X
			    88 separator-without        value 'S'.
				88 separator-blank          value 'B'.
				88 separator-slash          value '/'.
				88 separator-dot            value '.'.
				88 separator-hyphen         value '-'.
				88 separator-LocalDependent value 'L'.
              languageCode  pic X(02)
              countryCode   pic X(02)
    returning result        pic X(10).
procedure division.

end-declare.



declare function convertToDate private
    input     inputDate type DateDB2
    returning result    type Date.

procedure division.
end-declare.

declare function convertToDate private
    input     inputDate type DateJulian
    returning result    type Date.

procedure division.
end-declare.

declare function convertToDateDB2 private
    input     inputDate type Date
    returning result    type DateDB2.

procedure division.
end-declare.

declare function convertToDateDB2 private
    input     inputDate type DateJulian
    returning result    type DateDB2.

procedure division.
end-declare.

declare function convertToDateJulian private
    input     inputDate type Date
    returning result    type DateJulian.

procedure division.
end-declare.

declare function convertToDateJulian PRIVATE
    input     inputDate type DateDB2
    returning result    type DateJulian.

procedure division.
end-declare.


declare function isDateValid PRIVATE
                 input     inputDate  type Date
                 returning result     type Bool.
procedure division.
*incomplete test, but it's only for the example
  if inputDate::DD > 0 and inputDate::DD < 32
     set result to true
  else
     set result to false
  end-if
end-declare.
declare function isDateValid PRIVATE
                 input     inputDate  type DateDB2
                 returning result     type Bool.

procedure division.
*incomplete test, but it's only for the example
  if inputDate::DD > 0 and inputDate::DD < 32
     set result to true
  else
     set result to false
  end-if
end-declare.

declare function isDateValid PRIVATE
        input     inputDate   type DateJulian
        returning result      type Bool.

procedure division.
*incomplete test, but it's only for the example
  if inputDate::DD > 0 and inputDate::DD < 32
     set result to true
  else
     set result to false
  end-if
end-declare.



declare function addDaysToDate PRIVATE
input     dateToAdd    type Date
		  nbOFDays     pic 9(04)
returning result       type Date.

procedure division.
end-declare.


declare procedure addDaysToDate private
input     dateToAdd    type Date
		  nbOFDays     pic 9(04)
		  typeOfDays   pic X
		  calendar     pic X
output    result       type Date.

procedure division.
end-declare

declare function addDaysToDate PRIVATE
input		dateToAdd    type Date
			nbOFDays     pic 9(04)
			typeOfDays   pic X default 'E'
			calendar     pic X default 'C'
returning   result       type MonType.

procedure division.
end-declare



declare function addDaysToDate PRIVATE
input      dateToAdd     type Date
           nbOFDays      pic 9(04)
		   typeOfDays    pic X
		   calendar      pic X
returning  result        type Date.

procedure division.
end-declare.


declare function daysBetween PRIVATE
input     date1       type Date
          date2       type Date
returning result      pic 9(04).

procedure division.
end-declare.

.
⚠️ **GitHub.com Fallback** ⚠️