Scott,
Sorry for not specifing the format of the date. It *is* CCYYMMDD.
I was attempting to use the %timestamp bif to get my timestamp, but after seeing your example, I realize that by creating Date and Time fields concatenated into a TimeStamp data type field that it will do exactly what I need.
Jeff Young
Sr. Programmer Analyst
IBM -e(logo) server Certified Systems Exper - iSeries Technical Solutions V5R2
IBM Certified Specialist- e(logo) server i5Series Technical Solutions Designer V5R3
IBM Certified Specialist- e(logo)server i5Series Technical Solutions Implementer V5R3
________________________________
From: Scott Klement <rpg400-l@xxxxxxxxxxxxxxxx>
To: RPG programming on the AS400 / iSeries <rpg400-l@xxxxxxxxxxxx>
Sent: Wednesday, November 19, 2008 8:27:07 PM
Subject: Re: Create TimeStamp from numeric fields
Hi Jeff,
have a record containing 2 fields containing a numeric representation
of a date (8,2) and 2 associated fields containing a numeric
representation of an associated time (6,0).fields.
As so many others have said, I don't understand the 8,2 date. I don't
know what format that is? Is it YYYYMM.DD? Or YYMMDD.CC? Or, what is it?
Bearing in mind that I'm not sure how that date format works, I'll give
a sample with YYYYMM.DD dates -- and if that's not right, you might have
to modified this code accordingly:
D ts1 s Z
D ts2 s Z
D diff s 10i 0
/free
ts1 = %date( %dec(date1*100:8:0) : *ISO )
+ %time(time1:*HMS);
ts2 = %date( %dec(date2*100:8:0) : *ISO )
+ %time(time2:*HMS);
diff = %diff(ts1: ts2: *seconds);
The only thing that was even slightly tricky is that the first parameter
to %DATE() has to be a numeric field with no decimal places (or a
character field...) So I simply multiplied it by 100, and used %DEC()
to make the intermediate result be an 8,0 field. From there, the rest
was easy. Fairly basic %DATE() + %TIME() = %TIMESTAMP() logic.
Not sure why you brought up SQL. This is actually easier to do in RPG
than it would be in SQL (though, SQL is certainly capable, it'd require
a bit more work...)
As an Amazon Associate we earn from qualifying purchases.