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.