Midrange News for the IBM i Community


Posted by: raynesnf
Need help converting Date field to numeric field
has no ratings.
Published: 30 Jun 2016
Revised: 01 Jul 2016 - 356 days ago
Last viewed on: 22 Jun 2017 (775 views) 

Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.

Need help converting Date field to numeric field Published by: raynesnf on 30 Jun 2016 view comments(3)

Return to midrangenews.com home page.
Sort Ascend | Descend

COMMENTS

(Sign in to Post a Comment)
Posted by: Ringer
Premium member *
Comment on: Need help converting Date field to numeric field
Posted: 11 months 22 days 4 hours 49 minutes ago

Hlddat += %DAYS(120);       

S3cexp = %dec(Hlddat:*USA) ;

Ringer

 

Posted by: BrianR
Premium member *
Green Bay, WI
Comment on: Need help converting Date field to numeric field
Posted: 11 months 22 days 2 hours 28 minutes ago
Edited: Fri, 01 Jul, 2016 at 11:02:04 (356 days ago)

If you wanted to code this all in one line and get rid of the work variable:

S3cexp = %dec((%date(S3crap:*usa) + %DAYS(120)):*usa);

Posted by: bobcozzi
Site Admin ****
Chicagoland
Comment on: Need help converting Date field to numeric field
Posted: 11 months 21 days 22 hours 15 minutes ago

The problem is you are converting a date field to character and then attempting to convert that character field to numeric. However, *USA format in character form looks like this: "10/28/2016" therefore %DEC can not convert it, because of the dashes. You want to avoid the inner %CHAR(hlddat) and just convert the date field using %DEC with the optional 2nd parameter of the format in which you would like to return the date.