Open BrianGarland opened 3 years ago
Hi Brian - just heard your interview on the incredible i podcast.
Thank you for this timely post - In my shop we are rewriting some very old date arithmetic programs originally written in Synon /2e into an RPGLE service program that will use many of these built in functions.
Our shop uses dates in CYYMMDD format (where 0 in the century byte represents '19' and 1 in the Century byte represents '20').
We will likely be using the %Months built in function to add a months to a date, but not after converting the numeric value to a date field. I thought about using embedded SQL to do the date arithmetic, but it doesn't support our date format, where rpgle does with its *cymd format. Just shows that sometimes RPG is still best for some things :)
@JDubbTX , thanks for the comment. CYYMMDD is a bit of an od format. I've had to deal with it in the past.
If your application has been around for a while you probably have dates and times stored in some tables as numeric variables.
But, you use date and time data types for variables in your RPGLE programs to make the math easier, right?
There are many ways to convert from one data type to another. In the past developers have used data structures with overlapping subfields, or converting to character and then using substring.
Here are some examples of how to do this in a minimum amount of code. The examples work on IBM i 7.1 and newer.