RPGIV @ Work

A unique site for RPG and System i Lovers


Hi, this site will provide all what you need in System i and RPG developments.

My Name is Chamara Withanachchi, System i Expert and RPG Developer. And in the field for last 11 years.

I hope you will find lot of valuable information from this site

Extract part of date or time with %subdt Print E-mail
User Rating: / 1
Written by Chamara Withanachchi   

Define date field:

   D  ISOdate      S              D   datfmt(*ISO) inz(*SYS) 

If not initializing ISOdate to current system date (*SYS) in the D spec it is easy to get the system date:

     eval ISOdate  = %date()

Then select what part of the date you need with %subdt:

     eval curYear  = %subdt(ISOdate: *YEARS)
     eval curMonth = %subdt(ISOdate: *MONTHS)

How to retrieve the date one month prior to today:

eval ISOdate = %date() eval ISOdate = %date() - %months(1)

How to extract current minutes from time or timestamp as a character value:

/free curMinute = %char(%subdt(%time():*MN)); /end-free

Valid parameters:

*Days, *D, *Months, *M, *Years, *Y, *Seconds, *S, *Minutes, *MN, *Hours, *H (and *MSeconds, *MS for timestamps).
<Previous   Next>