User Date Special Words - Accessing the Job Date in Your RPG Programs

In this lesson we look at a small but very useful set of built-in special words that give your RPG program direct access to the job date. These words are handy when you need to print dates on reports, calculate age-based logic, or simply display the current job date without calling external APIs.

The User Date Special Words

RPG IV provides these eight special words:

  • UDATE and *DATE – the full job date
  • UMONTH and *MONTH – month only
  • UDAY and *DAY – day only
  • UYEAR and *YEAR – year only

All of them pull their value from the job date defined in the job description when your program starts. They are set once at program initialization and never change while the program runs (even if the job date is manually changed or the program runs past midnight).

Important Rules You Must Know

Here are the practical rules that apply every time you use these special words:

Output Formatting

  • UDATE prints as a 6-character numeric field (for example, 123125).
  • *DATE prints as an 8-character numeric field with a 4-digit year (for example, 20251231).
  • UMONTH, *MONTH, UDAY, *DAY, UYEAR print as 2-digit numeric fields.
  • *YEAR prints as a 4-digit numeric field.

Controlling the Date Format with DATEDIT

Use the DATEDIT keyword in your control specification to set the format for UDATE and *DATE:

DATEDIT value
UDATE format
*DATE format
*MDY
mmddyy
mmddyyyy (*USA)
*DMY
ddmmyy
ddmmyyyy (*EUR)
*YMD
yymmdd
yyyymmdd (*ISO)

If you do not code DATEDIT, the default is *MDY.

The same DATEDIT setting also controls how the Y edit code works on output.

Editing on Output

You can use the Y edit code in position 44 of output specifications with UDATE and *DATE. This inserts the separator character defined by DATEDIT (slash, period, etc.). Example: 12/31/2025 or 31.12.2025.

You cannot use the Y edit code with UMONTH, *MONTH, UDAY, *DAY, UYEAR or *YEAR.

What You Cannot Do with User Date Fields

These fields are read-only. You are not allowed to:

  • Use them in the result field of any calculation
  • Use them as Factor 1 on a PARM operation
  • Use them as the index on a LOOKUP operation
  • Use blank-after (B in output specs)
  • Define them as input fields

Where You Can Use User Date Fields

You can safely use them in:

  • Factor 1 or Factor 2 of calculation operations that accept numeric fields
  • Output specifications (with or without the Y edit code)

They Are Numeric, Not Date Data Type

Even though they contain dates, UDATE, *DATE, etc. are treated as numeric fields internally. If you need real date data type behavior, use the DATE data type and the TIME operation code instead.

Hints and Tips for Date Fields

  • For the current system date and time while the program is running, always use the TIME operation code or the %DATE / %TIME / %TIMESTAMP built-in functions. The user date special words are frozen at job start.
  • In modern free-form RPG, most developers prefer %DATE and the date data type because they are type-safe and much easier to work with.
  • Keep DATEDIT consistent across all your programs that print dates. Put it in a standard control specification /COPY member.
{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
>