× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



There are some APIs for date/time that might handle the formats you are working with - CEEDATM and CEESECS. In the documentation for the latter API, this interesting bit appears -

Each character in *picture_string* represents a character in *input_timestamp*. If delimiters such as the slash (/) appear in the picture string, leading zeros may be omitted. For example, these calls assign the same value to the variable /secs/.

CALL CEESECS('88/06/03 15.35.03',
'YY/MM/DD HH.MI.SS', secs, fc);

CALL CEESECS('88/6/3 15.35.03' ,
'YY/MM/DD HH.MI.SS', secs, fc);

CALL CEESECS('88/6/3 3.35.03 PM',
'YY/MM/DD HH.MI.SS AP', secs, fc);

CALL CEESECS('88.155 3.35.03 pm',
'YY.DDD HH.MI.SS AP', secs, fc);

Apparently on input, MM (01-12) and DD (01-31) are the same as ZM (1-12) and ZD (1-31). And if the time is left off, the API finishes off the time and microseconds in the timestamp for us.

After this you need to convert back to a different character representation using CEEDATM.

I'm not sure if the QWCCVTDT API tolerates the lack of leading zeroes - have never tried it much, if at all.

On 5/30/2012 9:26 AM, Jeff Young wrote:
Thanks Paul.
I used your solution and it works great.
Another tool in my toolbox.




On Wed, May 30, 2012 at 10:05 AM, Morgan, Paul<Paul.Morgan@xxxxxxxxxxx>wrote:

Jeff,

Convert the single digit months and days to two digits:

1) Check for / in position 2 and add a leading zero to convert to two
digit months.
2) Check for / in position 5 and insert a leading zero at position 4 to
convert to two digits days.

Now all dates are in mm/dd/ccyy format and should pass through your
conversion routine.

Paul Morgan

Principal Programmer Analyst
IT Supply Chain/Replenishment

-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx]
On Behalf Of Jeff Young
Sent: Wednesday, May 30, 2012 8:51 AM
To: rpg400-l@xxxxxxxxxxxx
Subject: Date Validation

All,
I have an application that needs to validate and convert a date from an
external system.
The format of the date can be m/d/ccyy,mm/d/ccyy,m/dd/ccyy,mm/dd/ccyy with
the "/" included.
The converted format needs to be a numeric field in the format ccyymmdd.

I have the following code in my program:
<snip>

// Edit Start Date

Monitor;

EpHOrDate = %Dec(%Date(Start_Date : *USA));

On-Error;

Load_Exception ('Start date is not a valid date');

EndMon;

// Edit Invoice Date

Monitor;

EpHInDate = %Dec(%Date(Invoice_Date : *USA));

On-Error;

Load_Exception('Invoice date is not a valid date');

EndMon;

</snip>
Where Start_Date and Invoice_Date are defined as 256A Varying and
EpHOrDate and EpHInDate are defined as 8p 0.

For values of 5/7/2012 for order date and 5/14/2012 for invoice date, the
code above rejects the order date, but accepts the invoice date.

I created a small test program to check the date editing process.
H Debug
D Date_in S 256A Varying
D Date_Out S 8 0
D Err S N
/Free
Monitor;
Date_Out = %Dec(%Date(Date_In : *USA));
On-Error;
Err = *On;
EndMon;

Return;

Using the values above, I set Date_In in DEBUG prior to the Monitor to each
of the dates.
BOTH of the dates were flagged as errors.

A. What am I doing wrong?
B. How can I handle the different date formats for editing and conversion?

The client is on V6R1M1

Thanks,

--
Jeff Young
Sr. Programmer Analyst
--
This is the RPG programming on the IBM i / System i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.


--
This is the RPG programming on the IBM i / System i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.