Problem solve Get help with specific problems with your technologies, process and projects.

Convert an ISO date into words

Here is a demonstration of how one line of RPG free-form code can convert an International Standard Date and Time Notation (ISO) to words.

Here is a demonstration of how one line of RPG free-form code can convert an International Standard Date and Time Notation (ISO) to words. This is a fairly complex statement; I don't normally recommend using the language in this manner. I made this exception as the formula is constant and therefore will not require deciphering in the future. The power and versatility of free code is demonstrated here. Pass the program an ISO date (example 1946-12-31) and it will return (Tuesday, December 31, 1946). I have been developing on IBM Midrange for 33 years and have seen RPG from the beginning. RPG Free-form is the latest and by far the most powerful and versatile form of RPG. I started using RPG Free-form about a year ago and do not intend on going back.
   
100      f*  Program ID        -  CDATE8G
02/09/05

    200      f*  Written By        -  James H. Greene

    300      f*  Date Written      -  2005/02/09
02/09/05

    400      f*  Purpose           -  return 30 character date in words

    500      f*                       example  Tuesday, December 31,
1946                                               02/09/05

    600      f*                       parm -isod- format 1946-12-31
02/09/05

    700
d*****************************************************************
02/09/05

    800      d isod            s               d   datfmt(*iso)
02/09/05

    900      d isodw           s               d   datfmt(*iso)
inz(d'0001-01-01')                                      02/09/05

   1000      d word            s             30a
02/08/05

   1100      d days            S              9    DIM(7) ctdata
perrcd(7)

   1200      d months          S              9    DIM(12) ctdata
perrcd(6)

   1300
d*****************************************************************
02/09/05

   1400       /free
02/08/05

   1500         word = %trim(days(%rem(%diff(isod:isodw:*days):7) + 1))
+ ', ' +                                        02/09/05

   1600                %trim(months(%subdt(isod:*m))) + ' '
+                                        02/09/05

   1700                %char(%subdt(isod:*d)) + ', '
+                                        02/09/05

   1800                %char(%subdt(isod:*y))
;                                        02/09/05

   1900         *inlr = *on
;                                        02/09/05

   2000       /end-free
02/08/05

   2100      c************************************************
02/09/05

   2200      c     *inzsr        begsr

   2300      c     *entry        plist

   2400      c                   parm                    isod
02/09/05

   2500      c                   parm                    word
02/08/05

   2600      c                   endsr

   2700      c************************************************
02/09/05

   2800 **     days of week

   2900 Monday   Tuesday  Wednesday Thursday Friday   Saturday Sunday

   3000 **     months of year

   3100 January  February March    April    May      June

   3200 July     August   September October  November December





                 * * * *  E N D  O F  S O U R C E  * ** * 

Dig Deeper on RPG iSeries programming

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close