Posts

Showing posts from September, 2017

AS400 Create CSV (IFS file) from PF

Below command will copy hte WRKFILE from Qtem to a CSV file in Directory DIR. CPYTOIMPF FROMFILE(QTEMP/WRKFILE) TOSTMF('/DIR/FILENAME.CSV') MBROPT(*REPLACE)   STMFCODPAG(*PCASCII) RCDDLM(*CRLF) ADDCOLNAM(*SYS) 

AS400 RPGLE: %date, %days Example

%Char((%Date - %Days(7)):*MDY/) If Current date is 9/29/17 the result of the above piece of code will give 9/22/17 ( ie - 7 days) Extract Date from a Timestamp fDate = %Date(%subst(%Char(%Timestamp()):1:10):*MDY/);  Difference between 2 dates, time or timestamp: %DIFF(op1:op2:*MSECONDS|*SECONDS|*MINUTES|*HOURS|*DAYS|*MONTHS|*YEARS) %DIFF(op1:op2:*MS|*S|*MN|*H|*D|*M|*Y) time_taken = %DIFF (%timestamp() : start_time : *SECONDS); Get Year/Month/Day from Date. and Hour/Min/Second from Timestamp: %SUBDT(value : unit { : digits { : decpos } }) *..1....+....2....+....3....+....4....+....5....+....6....+....7...+.... date = d'1999-02-17'; time = t'01.23.45'; timestamp = z'1999-02-17-01.23.45.98765'; num = %subdt(date:*YEARS); // num = 1999 num = %subdt(time:*MN); // num = 23 seconds = %subdt(timestamp:*S:5:3); // seconds = 45.987