How to convert character date to numeric date

1465 pts.
Tags:
AS/400
RPGLE
Hi All,
I have a character date field ('DD/MM/YYYY'). Now I want to convert into ISO numeric format in free format.
Thanks
1

Answer Wiki

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

Hi All,

Thanks for the valuable ideas below is the solution 
D @numC           S              8  0 inz(20041207)         
D @numD           S              6  0 inz(120804)           
D @Char           S             10    inz('21/10/2014')     
                      
C                                                           
 /Free                                                      
   //Convert Character DD/MM/YYYY to Numeric ISO            
    @numc=%dec(%date(%xlate('/':'.':@char):*eur.));         
    dsply @numc;                                            
 /End-free                                                   

Discuss This Question: 4  Replies

 
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.
  • philpl1jb

    This would convert the value in USA with no '-' to a date format

    Date( MyDDMMYYYY : *0USA)

    And this would convert it to decimal in ISO format

    %DEC(Date( MyDDMMYYYY : *0USA) : *ISO)


    54,090 pointsBadges:
    report
  • WilsonAlano
    Hi,

    There is no "direct" conversion from DD/MM/YYYY so you have some work to do before.

    //Converts to *EUR format
    MyDDMMYYYY = %ScanRpl('/' : '.' : MyDDMMYYY);
    // Converts to Numeric (NumDate is 8,0)
    NumDate = %Dec(%Date(MyDDMMYYYY:*EUR));

    Regards
    2,710 pointsBadges:
    report
  • WilsonAlano
    some useful expressions for date manipulation

    tDate: any date value
    EndofMonth, StartofMonth, StartYear: dates DaysInMonth, DaysinLastMonth, DayofMonth, Week: numeric (2,0)
    DayofYear: numeric (3,0)
    DayofWeek: numeric (1,0)
    ---------------------------
    StartofMonth=TDate-%days(%subdt(TDate:*d))+%days(1);
    EndofMonth=StartOfMonth+%months(1)-%days(1);
    DaysInMonth=%diff(EndofMonth:StartofMonth:*days)+1;
    DayofMonth=%subdt(Tdate:*d);
    DaysinLastMonth=%diff(StartofMonth-%days(1): EndofMonth-%months(1):*days)+1;
    StartYear=TDate-%days(%subdt(TDate:*d))-months(%subdt(TDate:*m))+%months(1)+%days(2);
    DayOfYear=%diff(TDate:StartYear:*d)+1;
    Week=%int(DayofYear/7)+1;
    DayofWeek=%abs(%rem(%diff(tDate:d'2001-12-16':*d):7));//0=Sunday 


    2,710 pointsBadges:
    report
  • philpl1jb

    thanks Wilson

    I was lost in the wrong part of the world.



    54,090 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.

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

Following

Share this item with your network: