## Convert an *iso date to *longjul in CLP

30 pts.
Tags:
CL Errors
CL Program
I am trying to convert an *iso date to a *longjul date in a CL program so I can subtract 6 days from today. It is crashing with a message "Date contains too many or too few numeric characters." My code is : Definitions dcl var(&julend) type(*char) len(7) dcl var(&jul) type(*dec) len(8 0) Code cvtdat date(&today) tovar(&julend) fromfmt(*iso) + tofmt(*longjul) tosep(*none) chgvar var(&jul) value(&julend) chgvar var(&jul) value(&jul - 6) chgvar var(&julend) value(&jul) cvtdat date(&julend) tovar(&begdte) + fromfmt(*longjul) tofmt(*iso) tosep(*none) I think my problem is I'm going from 2013-01-04 back 6 days to 2012-12-28. Am I using the correct number in my subtraction of 6 days ? Cheers, Jenny

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

## Discuss This Question: 4 Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
• If your starting date is '2013-01-04', the *LONGJUL value will be 2013004. The result of (2013004 - 6) will be 2012998. You probably can guess that the 998th day of 2012 will be quite a ways beyond the end of the year.   In general, you can't subtract numeric values from dates. You should only subtract "durations". However, CL doesn't support date duration operations.   You could write a small RPG (or COBOL, C or REXX) procedure and bind it into your program. Or you could code some ugly CL that manipulates values to simulate date duration math. Personally, since this already about CL, I would use the ILE CEE* date APIs to turn dates into numeric values and back into dates.   Here's a simple example that you can do some testing with: pgm ( + &FromDate + &NbrDays + &ResultDate + ) dcl &FromDate *char 10 dcl &NbrDays *dec ( 3 ) dcl &ResultDate *char 10 dcl &RtnVal1 *int dcl &RtnVal2 *int dcl &PicStr *char 10 value( 'YYYY-MM-DD' ) callprc CEEDAYS ( + &FromDate + &PicStr + &RtnVal1 + *omit + ) chgvar &RtnVal2 ( &RtnVal1 - &NbrDays ) callprc CEEDATE ( + &RtnVal2 + &PicStr + &ResultDate + *omit + ) Exit: return endpgm That proc receives a date in 'YYYY-MM-DD' format and a number of days. It subtracts the number of days from the date and returns the new resulting date. You can look at the documentation for CEEDAYS to see how it turns the date into a number. After the CL subtracts &NbrDays from that number, the API docs will describe how CEEDATE turns the new number back into a date.   Any discussion that you need for details can be continued here. I hope the formatting of the source code works out and you can read it. Be aware that this doesn't do any validation of the incoming values; the error code (function code, fc) is omitted. That can be covered if the docs are too confusing.   Tom