GREGDT: Converting From Julian to Gregorian Format

How to:

Reference:

The GREGDT function converts a date in Julian format (year-day) to Gregorian format (year-month-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; June21, 2004 in Julian format is 2004173.

Reference: Format Options 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:

  • If the format is I6 or I7, GREGDT returns the date in YMD format.
  • If the format is I8 or greater, GREGDT returns the date in YYMD format.

Syntax: How to Convert From Julian to Gregorian Format

GREGDT(indate, output)

where:

indate

I5 or I7

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 (zero).

output

I6, I8, I6YMD, or I8YYMD

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

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