Using Legacy Date Functions

The functions listed in this topic are legacy date functions. They were created for use with dates in integer, packed decimal, or alphanumeric format.

In this section:

Using Old Versions of Legacy Date Functions

Using Dates With Two- and Four-Digit Years

AYM: Adding or Subtracting Months to or From Dates

AYMD: Adding or Subtracting Days to or From a Date

CHGDAT: Changing Format of a Date

DA Functions: Converting a Date to an Integer

DMY, MDY, YMD: Calculating the Difference Between Two Dates

DOWK and DOWKL: Finding the Day of the Week

DT Functions: Converting an Integer to a Date

GREGDT: Converting From Julian to Gregorian Format

JULDAT: Converting From Gregorian to Julian Format

YM: Calculating Elapsed Months


Top of page

Using Old Versions of Legacy Date Functions

All legacy date functions support dates for the year 2000 and later. The old versions of these functions may not work correctly with dates after December 31, 1999. However, in some cases you may want to use the old version of a function, for example, if you do not use year 2000 dates. You can "turn off" the current version with the DATEFNS parameter.


Top of page

Syntax: How to Activate an Old Legacy Date Functions

SET DATEFNS = {ON|OFF}

where:

ON

Activates the function that supports dates for the year 2000 and later. This value is the default.

OFF

Deactivates a function that supports dates for the year 2000 and later.


Top of page

Using Dates With Two- and Four-Digit Years

Legacy date functions accept dates with two- or four-digit years. Four-digit years that display the century, such as 2000 or 1900, can be used if their formats are specified as I8YYMD, P8YYMD, D8YYMD, F8YYMD, or A8YYMD. Two‑digit years can use the DEFCENT and YRTHRESH parameters to assign century values if the field has a length of six (for example, I6YMD). For information on these parameters, see Customizing Your Environment in Developing Applications.

Example:

Using Four-Digit Years

Using Two-Digit Years


Top of page

Example: Using Four-Digit Years

The EDIT function creates dates with four-digit years. The functions JULDAT and GREGDAT then convert these dates to Julian and Gregorian formats.

DEFINE FILE EMPLOYEE
DATE/I8YYMD = EDIT('19'|EDIT(HIRE_DATE));
JDATE/I7 = JULDAT(DATE, 'I7');
GDATE/I8 = GREGDT(JDATE, 'I8');
END
TABLE FILE EMPLOYEE
PRINT DATE JDATE GDATE
END

The output is:

      DATE    JDATE     GDATE     
‑‑‑‑ ‑‑‑‑‑ ‑‑‑‑‑
1996/01/01 1996001 19960101
2001/01/01 2001001 20010101
2001/01/01 2001001 20010101
2001/01/01 2001001 20010101
1999/12/31 1999365 19991231

Top of page

Example: Using Two-Digit Years

The AYMD function returns an eight-digit date when the input argument has a six‑digit legacy date format. Since DEFCENT is 19 and YRTHRESH is 83, year values from 83 through 99 are interpreted as 1983 through 1999, and year values from 00 through 82 are interpreted as 2000 through 2082.

SET DEFCENT=19, YRTHRESH=83
DEFINE FILE EMPLOYEE
NEW_DATE/I8YYMD = AYMD(EFFECT_DATE, 30, 'I8');
END
TABLE FILE EMPLOYEE
PRINT EFFECT_DATE NEW_DATE BY EMP_ID
END

The output is:

EMP_ID     EFFECT_DATE    NEW_DATE
------ ----------- --------
071382660
112847612
117593129 82/11/01 2082/12/01
119265415
119329144 83/01/01 1983/01/31
123764317 83/03/01 1983/03/31
126724188
219984371
326179357 82/12/01 2082/12/31
451123478 84/09/01 1984/10/01
543729165
818692173 83/05/01 1983/05/31

Top of page

AYM: Adding or Subtracting Months to or From Dates

Available Operating Systems: OS/390, UNIX, VM/CMS

Available Languages: reporting, Maintain

How to:

Add or Subtract Months to or From a Date

Example:

Adding Months to a Date

The AYM function adds months to or subtracts months from a date in year-month format. You can convert a date to this format using the CHGDAT or EDIT function.


Top of page

Syntax: How to Add or Subtract Months to or From a Date

AYM(indate, months, outfield)

where:

indate

Numeric

Is the original date in year-month format, the name of a field that contains the date, or an expression that returns the date. If the date is not valid, the function returns a 0.

months

Integer

Is the number of months you are adding to or subtracting from the date. To subtract months, use a negative number.

outfield

Integer

Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks.

In Dialogue Manager, you must specify the format. In Maintain, you must specify the name of the field.


Top of page

Example: Adding Months to a Date

The COMPUTE command converts the dates in HIRE_DATE from year‑month‑day to year‑month format and stores the result in HIRE_MONTH. AYM then adds six months to HIRE_MONTH and stores the result in AFTER6MONTHS.

TABLE FILE EMPLOYEE
PRINT HIRE_DATE AND COMPUTE
HIRE_MONTH/I4YM = HIRE_DATE/100 ;
AFTER6MONTHS/I4YM = AYM(HIRE_MONTH, 6, AFTER6MONTHS);
BY LAST_NAME BY FIRST_NAME
WHERE DEPARTMENT EQ 'MIS';
END

The output is:

LAST_NAME        FIRST_NAME  HIRE_DATE  HIRE_MONTH  AFTER6MONTHS
‑‑‑‑‑‑‑‑‑ ‑‑‑‑‑‑‑‑‑‑ ‑‑‑‑‑‑‑‑‑ ‑‑‑‑‑‑‑‑‑‑ ‑‑‑‑‑‑‑‑‑‑‑‑
BLACKWOOD ROSEMARIE 82/04/01 82/04 82/10
CROSS BARBARA 81/11/02 81/11 82/05
GREENSPAN MARY 82/04/01 82/04 82/10
JONES DIANE 82/05/01 82/05 82/11
MCCOY JOHN 81/07/01 81/07 82/01
SMITH MARY 81/07/01 81/07 82/01

Top of page

AYMD: Adding or Subtracting Days to or From a Date

Available Operating Systems: OS/390, UNIX, VM/CMS

Available Languages: reporting, Maintain

How to:

Add or Subtract Days to or From a Date

Example:

Adding Days to a Date

The AYMD function adds days to or subtracts days from a date in year-month-day format. You can convert a date to this format using the CHGDAT or EDIT function.

If the addition or subtraction of days crosses forward or backward into another century, the century digits of the output year are adjusted.


Top of page

Syntax: How to Add or Subtract Days to or From a Date

AYMD(indate, days, outfield)

where:

indate

Numeric

Is the original date in year-month-day format, the name of a field that contains the date, or an expression that returns the date. If indate is a field name, the field format must be I6, I6YMD, I8, I8YYMD, P6, P6YMD, F6, F6YMD, D6, or D6YMD. If the date is not valid, the function returns a 0.

days

Integer

Is the number of days you are adding to or subtracting from indate. To subtract days, use a negative number.

outfield

I6, I6YMD, I8, or I8YYMD

Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks. If indate is a field, outfield must have the same format.

In Dialogue Manager, you must specify the format. In Maintain, you must specify the name of the field.


Top of page

Example: Adding Days to a Date

AYMD adds 35 days to each value in the HIRE_DATE field, and stores the result in AFTER35DAYS:

TABLE FILE EMPLOYEE
PRINT HIRE_DATE AND COMPUTE
AFTER35DAYS/I6YMD = AYMD(HIRE_DATE, 35, AFTER35DAYS);
BY LAST_NAME BY FIRST_NAME
WHERE DEPARTMENT EQ 'PRODUCTION';
END

The output is:

LAST_NAME        FIRST_NAME  HIRE_DATE  AFTER35DAYS
‑‑‑‑‑‑‑‑‑ ‑‑‑‑‑‑‑‑‑‑ ‑‑‑‑‑‑‑‑‑ ‑‑‑‑‑‑‑‑‑‑‑
BANNING JOHN 82/08/01 82/09/05
IRVING JOAN 82/01/04 82/02/08
MCKNIGHT ROGER 82/02/02 82/03/09
ROMANS ANTHONY 82/07/01 82/08/05
SMITH RICHARD 82/01/04 82/02/08
STEVENS ALFRED 80/06/02 80/07/07

Top of page

CHGDAT: Changing Format of a Date

Available Operating Systems: OS/390, UNIX, VM/CMS

Available Languages: reporting, Maintain

How to:

Change the Format of a Date

Example:

Converting From YMD to MDYYX Format

Reference:

Short to Long Format Conversion

The CHGDAT function rearranges the year, month, and day portions of a date and converts a date between long and short date format. Long format contains the year, month, and day; short format contains one or two of these elements, such as year and month, or just day. A format can specify either two digits for the year (for example, 97), or four digits (for example, 1997).

Note: Since CHGDAT returns the date in alphanumeric format with 17 characters, use the EDIT function to truncate this field or convert the date to numeric format.

The format of the date to be converted and the resulting date contain the following characters in any combination:

D

Day of the month (01 through 31).

M

Month of the year (01 through 12).

Y[Y]

Year. Y indicates a two‑digit year (such as 94); YY indicates a four‑digit year (such as 1994).

To spell out the month rather than use a number, append one of the following to the format of the resulting date:

T

Displays the month as a three‑letter abbreviation.

X

Displays the full name of the month.

The function ignores any other character in the format.


Top of page

Reference: Short to Long Format Conversion

If you are converting a date from short to long format (for example, from year‑month to year‑month‑day), the function supplies the portion of the date missing in the short format, as shown in the following table:

Portion of Date Missing

Portion Supplied by Function

Day (for example, from YM to YMD)

Last day of the month.

Month (for example, from Y to YM)

Last month of the year (December).

Year (for example, from MD to YMD)

The year 99.

Converting year from two-digit to four-digit (for example, from YMD to YYMD)

If DATEFNS=ON, the century will be determined by the 100‑year window defined by DEFCENT and YRTHRESH. See Customizing Your Environment in Developing Applications or Working With Cross-Century Dates in the iBase archive for details on DEFCENT and YRTHRESH.

If DATEFNS=OFF, the year 19xx is supplied, where xx is the last two digits in the year.


Top of page

Syntax: How to Change the Format of a Date

CHGDAT('oldformat', 'newformat', indate, outfield)

where:

'oldformat'

A5

Is the format of the original date enclosed in single quotation marks.

'newformat'

A5

Is the format of the converted date enclosed in single quotation marks.

indate

Alphanumeric

Is the original date. If the date is in numeric format, change it to alphanumeric format using the EDIT function. If the input date is invalid, the function returns spaces.

outfield

Alphanumeric or A17

Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks.

In Dialogue Manager, you must specify the format. In Maintain, you must specify the name of the field.


Top of page

Example: Converting From YMD to MDYYX Format

The EDIT function changes HIRE_DATE from numeric to alphanumeric format. CHGDAT then converts each value in ALPHA_HIRE from YMD to MDYYX format and stores the result in HIRE_MDY, which has the format A17. The option X in the new format displays the full name of the month.

TABLE FILE EMPLOYEE
PRINT HIRE_DATE AND COMPUTE
ALPHA_HIRE/A17 = EDIT(HIRE_DATE); NOPRINT AND COMPUTE
HIRE_MDY/A17 = CHGDAT('YMD', 'MDYYX', ALPHA_HIRE, 'A17');
BY LAST_NAME BY FIRST_NAME
WHERE DEPARTMENT EQ 'PRODUCTION';
END

The output is:

LAST_NAME        FIRST_NAME  HIRE_DATE  HIRE_MDY
‑‑‑‑‑‑‑‑‑ ‑‑‑‑‑‑‑‑‑‑ ‑‑‑‑‑‑‑‑‑ ‑‑‑‑‑‑‑‑
BANNING JOHN 82/08/01 AUGUST 01 1982
IRVING JOAN 82/01/04 JANUARY 04 1982
MCKNIGHT ROGER 82/02/02 FEBRUARY 02 1982
ROMANS ANTHONY 82/07/01 JULY 01 1982
SMITH RICHARD 82/01/04 JANUARY 04 1982
STEVENS ALFRED 80/06/02 JUNE 02 1980

Top of page

DA Functions: Converting a Date to an Integer

Available Operating Systems: All

Available Languages: reporting, Maintain

How to:

Convert a Date to an Integer

Example:

Converting Dates and Calculating the Difference Between Them

The DA functions convert a date to the number of days between December 31, 1899 and that date. By converting a date to the number of days, you can add and subtract dates and calculate the intervals between them. You can convert the result back to a date using the DT functions discussed in DT Functions: Converting an Integer to a Date.

There are six DA functions; each one accepts a date in a different format.


Top of page

Syntax: How to Convert a Date to an Integer

function(indate, outfield)

where:

function

Is one of the following:

DADMY converts a date in day‑month‑year format.

DADYM converts a date in day‑year‑month format.

DAMDY converts a date in month‑day‑year format.

DAMYD converts a date in month‑year‑day format.

DAYDM converts a date in year‑day‑month format.

DAYMD converts a date in year‑month‑day format.

indate

Numeric

Is the date to be converted, or the name of a field that contains the date. The date is truncated to an integer before conversion. The format of the date depends on the function.

To specify the year, enter only the last two digits; the function assumes the century component. If the date is invalid, the function returns a 0.

outfield

Integer

Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks.

In Dialogue Manager, you must specify the format. In Maintain, you must specify the name of the field.


Top of page

Example: Converting Dates and Calculating the Difference Between Them

DAYMD converts the DAT_INC and HIRE_DATE fields to the number of days since December 31, 1899, and the smaller number is then subtracted from the larger number:

TABLE FILE EMPLOYEE
PRINT DAT_INC AS 'RAISE DATE' AND COMPUTE
DAYS_HIRED/I8 = DAYMD(DAT_INC, 'I8') ‑ DAYMD(HIRE_DATE, 'I8');
BY LAST_NAME BY FIRST_NAME
IF DAYS_HIRED NE 0
WHERE DEPARTMENT EQ 'PRODUCTION';
END

The output is:

LAST_NAME        FIRST_NAME  RAISE DATE  DAYS_HIRED
‑‑‑‑‑‑‑‑‑ ‑‑‑‑‑‑‑‑‑‑ ‑‑‑‑‑‑‑‑‑‑ ‑‑‑‑‑‑‑‑‑‑
IRVING JOAN 82/05/14 130
MCKNIGHT ROGER 82/05/14 101
SMITH RICHARD 82/05/14 130
STEVENS ALFRED 82/01/01 578
81/01/01 213

Top of page

DMY, MDY, YMD: Calculating the Difference Between Two Dates

Available Operating Systems: All

Available Languages: reporting, Maintain

How to:

Calculate the Difference Between Two Dates

Example:

Calculating the Number of Days Between Two Dates

The DMY, MDY, and YMD functions calculate the difference between two dates in integer, alphanumeric, or packed format.


Top of page

Syntax: How to Calculate the Difference Between Two Dates

function(begin, end)

where:

function

Is one of the following:

DMY calculates the difference between two dates in day‑month‑year format.

MDY calculates the difference between two dates in month‑day‑year format.

YMD calculates the difference between two dates in year‑month‑day format.

begin

Numeric

Is the beginning date, or the name of a field that contains the date.

end

Numeric

Is the end date, or the name of a field that contains the date.


Top of page

Example: Calculating the Number of Days Between Two Dates

YMD calculates the number of days between the dates in HIRE_DATE and DAT_INC:

TABLE FILE EMPLOYEE
SUM HIRE_DATE FST.DAT_INC AS 'FIRST PAY,INCREASE' AND COMPUTE
DIFF/I4 = YMD(HIRE_DATE, FST.DAT_INC); AS 'DAYS,BETWEEN'
BY LAST_NAME BY FIRST_NAME
WHERE DEPARTMENT EQ 'MIS';
END

The output is:

                                        FIRST PAY  DAYS
LAST_NAME FIRST_NAME HIRE_DATE INCREASE BETWEEN
--------- ---------- --------- --------- -------
BLACKWOOD ROSEMARIE 82/04/01 82/04/01 0
CROSS BARBARA 81/11/02 82/04/09 158
GREENSPAN MARY 82/04/01 82/06/11 71
JONES DIANE 82/05/01 82/06/01 31
MCCOY JOHN 81/07/01 82/01/01 184
SMITH MARY 81/07/01 82/01/01 184

Top of page

DOWK and DOWKL: Finding the Day of the Week

Available Operating Systems: All

Available Languages: reporting, Maintain

How to:

Find the Day of the Week

Example:

Finding the Day of the Week

The DOWK and DOWKL functions find the day of the week that corresponds to a date. DOWK returns the day as a three letter abbreviation; DOWKL displays the full name of the day.


Top of page

Syntax: How to Find the Day of the Week

{DOWK|DOWKL}(indate, outfield)

where:

indate

Numeric

Is the input date in year‑month‑day format. If the date is not valid, the function returns spaces. If the date specifies a two digit year and DEFCENT and YRTHRESH values have not been set, the function assumes the 20th century.

outfield

DOWK: A4

DOWKL: A12

Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks.

In Dialogue Manager, you must specify the format. In Maintain, you must specify the name of the field.


Top of page

Example: Finding the Day of the Week

DOWK determines the day of the week that corresponds to the value in the HIRE_DATE field and stores the result in DATED:

TABLE FILE EMPLOYEE
PRINT EMP_ID AND HIRE_DATE AND COMPUTE
DATED/A4 = DOWK(HIRE_DATE, DATED);
WHERE DEPARTMENT EQ 'PRODUCTION';
END

The output is:

EMP_ID     HIRE_DATE  DATED
‑‑‑‑‑‑ ‑‑‑‑‑‑‑‑‑ ‑‑‑‑‑
071382660 80/06/02 MON
119265415 82/01/04 MON
119329144 82/08/01 SUN
123764317 82/01/04 MON
126724188 82/07/01 THU
451123478 82/02/02 TUE

Top of page

DT Functions: Converting an Integer to a Date

Available Operating Systems: All

Available Languages: reporting, Maintain

How to:

Convert an Integer to a Date

Example:

Converting an Integer to a Date

The DT functions convert an integer representing the number of days elapsed since December 31, 1899 to the corresponding date. They are useful when you are performing arithmetic on a date converted to the number of days (see DA Functions: Converting a Date to an Integer). The DT functions convert the result back to a date.

There are six DT functions; each one converts a number into a date of a different format.


Top of page

Syntax: How to Convert an Integer to a Date

function(number, outfield)

where:

function

Is one of the following:

DTDMY converts a number to a day‑month‑year date.

DTDYM converts a number to a day‑year‑month date.

DTMDY converts a number to a month‑day‑year date.

DTMYD converts a number to a month‑year‑day date.

DTYDM converts a number to a year‑day‑month date.

DTYMD converts a number to a year‑month‑day date.

number

Numeric

Is the number of days since December 31, 1899. The number is truncated to an integer.

outfield

Integer

Is the name of the field containing the result or the format of the output value enclosed in single quotation marks. The output format depends on the function being used.

In Dialogue Manager, you must specify the format. In Maintain, you must specify the name of the field.


Top of page

Example: Converting an Integer to a Date

DTMDY converts the NEWF field (which was converted to the number of days by DAYMD) to the corresponding date and stores the result in NEW_HIRE_DATE:

-* THIS PROCEDURE CONVERTS HIRE_DATE, WHICH IS IN I6YMD FORMAT,
-* TO A DATE IN I8MDYY FORMAT.
-* FIRST IT USES THE DAYMD FUNCTION TO CONVERT HIRE_DATE
-* TO A NUMBER OF DAYS.
-* THEN IT USES THE DTMDY FUNCTION TO CONVERT THIS NUMBER OF
-* DAYS TO I8MDYY FORMAT
-*
DEFINE FILE EMPLOYEE
NEWF/I8 WITH EMP_ID = DAYMD(HIRE_DATE, NEWF);
NEW_HIRE_DATE/I8MDYY WITH EMP_ID = DTMDY(NEWF, NEW_HIRE_DATE);
END
TABLE FILE EMPLOYEE
PRINT HIRE_DATE NEW_HIRE_DATE
BY FN BY LN
WHERE DEPARTMENT EQ 'MIS'
END

The output is:

FIRST_NAME  LAST_NAME        HIRE_DATE  NEW_HIRE_DATE
---------- --------- --------- -------------
BARBARA CROSS 81/11/02 11/02/1981
DIANE JONES 82/05/01 05/01/1982
JOHN MCCOY 81/07/01 07/01/1981
MARY GREENSPAN 82/04/01 04/01/1982
SMITH 81/07/01 07/01/1981
ROSEMARIE BLACKWOOD 82/04/01 04/01/1982

Top of page

GREGDT: Converting From Julian to Gregorian Format

Available Operating Systems: All

Available Languages: reporting, Maintain

The GREGDT function converts a date in Julian format to Gregorian format (year‑month‑day).

How to:

Convert From Julian to Gregorian Format

Example:

Converting From Julian to Gregorian Format

Reference:

DATEFNS Settings for GREGDT

A date in Julian format is a five- or seven‑digit number. The first two or four digits are the year; the last three digits are the number of the day, counting from January 1. For example, January 1, 1999 in Julian format is either 99001 or 1999001.


Top of page

Reference: DATEFNS Settings for GREGDT

GREGDT converts a Julian date to either YMD or YYMD format using the DEFCENT and YRTHRESH parameter settings to determine the century, if required. GREGDT returns a date as follows:

DATEFNS Setting

I6 or I7 Format

I8 Format or Greater

ON

YMD

YYMD

OFF

YMD

YMD


Top of page

Syntax: How to Convert From Julian to Gregorian Format

GREGDT(indate, outfield)

where:

indate

Numeric

Is the Julian date, which is truncated to an integer before conversion. Each value must be a five- or seven‑digit number after truncation. If the date is invalid, the function returns a 0.

outfield

I6 or I8

Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks.

In Dialogue Manager, you must specify the format. In Maintain, you must specify the name of the field.


Top of page

Example: Converting From Julian to Gregorian Format

GREGDT converts the JULIAN field to YYMD (Gregorian) format. It determines the century using the default DEFCENT and YRTHRESH parameter settings.

TABLE FILE EMPLOYEE
PRINT HIRE_DATE AND
COMPUTE JULIAN/I5 = JULDAT(HIRE_DATE, JULIAN); AND
COMPUTE GREG_DATE/I8 = GREGDT(JULIAN, 'I8');
BY LAST_NAME BY FIRST_NAME
WHERE DEPARTMENT EQ 'PRODUCTION';
END

The output is:

LAST_NAME        FIRST_NAME  HIRE_DATE  JULIAN  GREG_DATE
--------- ---------- --------- ------ ---------
BANNING JOHN 82/08/01 82213 19820801
IRVING JOAN 82/01/04 82004 19820104
MCKNIGHT ROGER 82/02/02 82033 19820202
ROMANS ANTHONY 82/07/01 82182 19820701
SMITH RICHARD 82/01/04 82004 19820104
STEVENS ALFRED 80/06/02 80154 19800602

Top of page

JULDAT: Converting From Gregorian to Julian Format

Available Operating Systems: All

Available Languages: reporting, Maintain

How to:

Convert From Gregorian to Julian Format

Reference:

DATEFNS Settings for JULDAT

Example:

Converting From Gregorian to Julian Format

The JULDAT function converts a date from Gregorian format (year‑month‑day) to Julian format (year‑day). A date in Julian format is a five- or seven-digit number. The first two or four digits are the year; the last three digits are the number of the day, counting from January 1. For example, January 1, 1999 in Julian format is either 99001 or 1999001.


Top of page

Reference: DATEFNS Settings for JULDAT

JULDAT converts a Gregorian date to either YYNNN or YYYYNNN format, using the DEFCENT and YRTHRESH parameter settings to determine if the century is required.

JULDAT returns dates as follows:

DATEFNS Setting

I5 or I6 Format

I7 Format or Greater

ON

YYNNN

YYYYNNN

OFF

YYNNN

YYNNN


Top of page

Syntax: How to Convert From Gregorian to Julian Format

JULDAT(indate, outfield)

where:

indate

Numeric

Is the date or the name of the field that contains the date in year‑month‑day format (YMD or YYMD).

outfield

I5 or I7

Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks.

In Dialogue Manager, you must specify the format. In Maintain, you must specify the name of the field.


Top of page

Example: Converting From Gregorian to Julian Format

JULDAT converts the HIRE_DATE field to Julian format. It determines the century using the default DEFCENT and YRTHRESH parameter settings.

TABLE FILE EMPLOYEE
PRINT HIRE_DATE AND COMPUTE
JULIAN/I7 = JULDAT(HIRE_DATE, JULIAN);
BY LAST_NAME BY FIRST_NAME
WHERE DEPARTMENT EQ 'PRODUCTION';
END

The output is:

LAST_NAME        FIRST_NAME  HIRE_DATE   JULIAN
--------- ---------- --------- ------
BANNING JOHN 82/08/01 1982213
IRVING JOAN 82/01/04 1982004
MCKNIGHT ROGER 82/02/02 1982033
ROMANS ANTHONY 82/07/01 1982182
SMITH RICHARD 82/01/04 1982004
STEVENS ALFRED 80/06/02 1980154

Top of page

YM: Calculating Elapsed Months

Available Operating Systems: All

Available Languages: reporting, Maintain

How to:

Calculate Elapsed Months

Example:

Calculating Elapsed Months

The YM function calculates the number of months that elapse between two dates. The dates must be in year‑month format. You can convert a date to this format by using the CHGDAT or EDIT function.


Top of page

Syntax: How to Calculate Elapsed Months

YM(fromdate, todate, outfield)

where:

fromdate

Numeric

Is the start date in year‑month format (for example, I4YM). If the date is not valid, the function returns a 0.

todate

Numeric

Is the end date in year‑month format. If the date is not valid, the function returns a 0.

outfield

Integer

Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks.

In Dialogue Manager, you must specify the format. In Maintain, you must specify the name of the field.


Top of page

Example: Calculating Elapsed Months

The COMPUTE commands convert the dates from year‑month‑day to year‑month format; then YM calculates the difference between the values in the HIRE_DATE/100 and DAT_INC/100 fields:

TABLE FILE EMPLOYEE
PRINT DAT_INC AS 'RAISE DATE' AND COMPUTE
HIRE_MONTH/I4YM = HIRE_DATE/100; NOPRINT AND COMPUTE
MONTH_INC/I4YM = DAT_INC/100; NOPRINT AND COMPUTE
MONTHS_HIRED/I3 = YM(HIRE_MONTH, MONTH_INC, 'I3');
BY LAST_NAME BY FIRST_NAME BY HIRE_DATE
IF MONTHS_HIRED NE 0
WHERE DEPARTMENT EQ 'MIS';
END

The output is:

LAST_NAME        FIRST_NAME  HIRE_DATE  RAISE DATE  MONTHS_HIRED
‑‑‑‑‑‑‑‑‑ ‑‑‑‑‑‑‑‑‑‑ ‑‑‑‑‑‑‑‑‑ ‑‑‑‑‑‑‑‑‑‑ ‑‑‑‑‑‑‑‑‑‑‑‑
CROSS BARBARA 81/11/02 82/04/09 5
GREENSPAN MARY 82/04/01 82/06/11 2
JONES DIANE 82/05/01 82/06/01 1
MCCOY JOHN 81/07/01 82/01/01 6
SMITH MARY 81/07/01 82/01/01 6