Extracting details from timestamps…

pts.
Tags:
RPGLE
I have a timestamp field from which I need to extract the date portion into a packed(7,0) field in *cymd format and the time portion into a packed(6,0) field in *hms format. We're running V5R3. What is the neatest way to achieve this?

Answer Wiki

Thanks. We'll let you know when a new response is added.

Just use MOVE like this:

*CYMD MOVE Datestamp Packeddate

as long as the datestamp is in the correct format for your program (DATFMT on the header specs) the system does it for you. It also works the other way round, but it’s wise to use TEST(D) first to check it’s valid before moving packed to date / datestamp fields.

===========================================================

The MOVE op-code with *CYMD is correct except it can’t be used with a timestamp in factor 2 because *CYMD isn’t a valid timestamp format. The timestamp must be converted to a date first:<pre>
d ts s z inz( *sys )
d dt s d
d dtd s 7p 0

C eval dt = %date( ts )
C *cymd move dt dtd</pre>
After the date portion of the timestamp (ts) is put into a date field (dt), the date can be MOVEd into a packed-decimal field (dtd) in *CYMD format.

Extracting the time should also be a two-step operation. Getting the date and time portions into actual date and time fields needs to be separated from the conversion to a non-standard format. Future maintenance should see the detailed steps.

Tom

Discuss This Question: 1  Reply

 
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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Jwebb901
    Use the %SUBDT BIF
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following