%Days, %Months, %Years functions
We always need to add or subtract few months, days, years to a specific date or find the time-period in years, days or months. In this article we will learn this special mathematics.
First step to perform date mathematics:-
This step and the last step would not be required if we are dealing with an actual date, a date field which has been defined to be of date data type. However, in most of the cases, this would not be the practical case. We will get a date in numeric or character format. So, first step would be to convert these numeric and character program date fields into an actual date field. Did the format of this date come into your mind? Well, once a date acquires its own data type, date formats do not matter.
Converting a numeric date field into actual date data type is a one step process. To learn more about how to convert numeric date field into actual date data type, refer this article. Ok, once we have got a date field, we should begin with our actual basic mathematics.
Last step to perform date mathematics:-
The last step in performing date mathematics is to get the date back into the original numeric format.
The concept is further clarified with the examples given below.
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++
D W@YMD S 6 0 Inz(000101)
D W@Date S D
* First step is to get an actual date
CL0N01Factor1+++++++Opcode&ExtFactor2+++++++Result+++
C *YMD Move W@YMD W@Date
* Add 5 years
C Eval W@Date += %Years(5)
* Add 11 months
C Eval W@Date += %Months(11)
* Add 30 days
C Eval W@Date += %Days(30)
C *YMD Move W@Date W@YMD
C W@YMD Dsply
C Return Output:-
DSPLY 51231
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++
D W@YMD S 6 0 Inz(000101)
D W@Date S D
D W@Date2 S 6 0
* First step is to get an actual date
CL0N01Factor1+++++++Opcode&ExtFactor2+++++++Result+++
C *YMD Move W@YMD W@Date
* Sutract 5 years
C Eval W@Date -= %Years(5)
* Subtract 11 months
C Eval W@Date -= %Months(11)
* Subtract 30 days
C Eval W@Date -= %Days(30)
C *YMD Move W@Date W@YMD
C W@YMD Dsply
C Return Output:-
DSPLY 940102
Recent comments
5 days 1 hour ago
5 days 2 hours ago
5 days 2 hours ago
5 days 4 hours ago
5 days 15 hours ago
5 days 17 hours ago
5 days 18 hours ago
5 days 19 hours ago
6 days 8 hours ago
6 days 18 hours ago