Hi Scott,
if your procedure should be international you should add date separator ".".
This is the way how the date is formatted in several (European) countries,
such as Germany!
We will code 31.12.09 for the last day of 2009!
I have a comparable routine which checks the passed date format and
separator and converts the date based on this format.
If no date format and/or separator passed, I retrieve the job's date format
and date separator.
BTW the BIFs work for character dates with a 4 digit year where the leading
zero for month and day are not specified.
That means 1/1/2009 is checked and converted correctly.
Mit freundlichen Grüßen / Best regards
Birgitta Hauser
"Shoot for the moon, even if you miss, you'll land among the stars." (Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them
and keeping them!"
-----Ursprüngliche Nachricht-----
Von: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] Im
Auftrag von Scott Klement
Gesendet: Thursday, 17. December 2009 22:37
An: RPG programming on the IBM i / System i
Betreff: Re: Expanding Dates
FWIW, my solution to this problem was to write a subprocedure, and put
it into our "common utilities" service program. The pseudo code (off
the top of my head) to this subprocedure is as follows:
1) %scan for -. If found, this is the date sep.
2) if not -, %scan for /, if found this is the date sep.
3) if not either - or /, assume there's no date sep.
4) if no date sep, and the input string <6 chars long, pad it to 6 chars
by adding zeros to the left. Then %subst into MMDDYY
5) if no date sep and the input string <8 chars long, but >6 chars, pad
it to 8 chars by adding zeros to the left, then %subst into MMDDYYYY
6) if there's a date sep, then use the date sep to break into 3 fields,
M, D and Y. (This is done with the %scan and %subst BIFs)
7) At this point, no matter what the input, the data should be split
into an M, D and Y field. If Y<100, add 2000 to it.
8) Concatenate the M, D and Y fields (left padding each with zeros where
needed) to make a YYYY-MM-DD field.
9) Convert to a date field, and return the date field.
The idea here is that user can type 1/5/9 or 01/5/9 or 1/05/09 or
whatever they like, and it'll do it's best to figure it out as a date
field. Since our users all live in the USA, and all grew up with MDY
dates, we assume the date is in MDY sequence.
If I had wanted this to be universal, I would've passed an extra
parameter to the routine to indicate whether MDY, DMY or YMD was the
appropriate sequence for the month/day/year fields, but in my shop
that's not needed.
But the point is... it separates the fields into their month, day and
year components based on the date separators rather than forcing them to
be in a specific position, so the user doesn't have to zero-fill things.
I use this in all of my web applications, and occasionally even in
green-screen apps so give the user more flexibility on how they enter
dates. Once it's been converted to a date field, I can easily use it
with any of the RPG BIFS, etc, to get it into other formats when needed.
Buddy McClean wrote:
Thanks,
To be accepted for RPG date bifs/opcodes. So far they have not z-sup the 2
digit year.
I was disapointed that the opcodes could not expand the numbers in dates
that had a divider, but I'm over it.
I will have to investigate the CEE part, I claim ignorance.
As an Amazon Associate we earn from qualifying purchases.