ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Date Conversion

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Date Conversion

    Hey again,
    i have on my rpg display screen a date field which format is DDMMYYYY
    but when i want to store it in the physical file i want it to be in the format :
    CYYMMDD (where C means century)

    how can i from the DDMMYYYY format know the appropriate century...
    can anyone help me in this issue..

    Thx alot inadvance

  • #2
    Re: Date Conversion

    Hello

    Try this one:
    Code:
    DDate1            S              8  0 Inz(11062007)                
    DDate2            S              8S 0                              
    DDDMMYYYY         S               D   DatFmt(*EUR)                 
    DYYYYMMDD         S               D   DatFmt(*ISO)                 
    C                   Move      Date1         DDMMYYYY               
    C                   Eval      YYYYMMDD = DDMMYYYY                  
    C                   Move      YYYYMMDD      Date2                  
    C                   Seton                                        LR

    Comment


    • #3
      Re: Date Conversion

      Hi,

      assumed the field in the display file and the field in the physical file are both numeric, try the following:
      PHP Code:
       /Free
          
      //Release V5R3 or higher
          
      MyCYMD = %Dec(%Date(MyDMYY: *EUR): *CYMD);

          //Release V5R2
          
      MyCYMD = %Int(%Char(%Date(MyDMYY: *EUR): *CYMD0));
       /
      End-Free 
      Birgitta

      Comment


      • #4
        Re: Date Conversion

        I have my two dates in the input file in the format of YYMMDD in char format, now I converted the dates to CCYYMMDD

        Code:
        C                   eval      t_year  =     %subst(PBDATE:1:2)    
        C                   eval      t_month =     %subst(PBDATE:3:2)    
        C                   eval      t_day   =     %subst(PBDATE:5:2)    
        C     *ymd          move      TEMP_BIRTH_DT TEMP_DOB_ISO          
        C                   MOVE      TEMP_DOB_ISO  temp_DOB_date1        
        C                   MOVE      temp_DOB_date1temp_DOB_date         
        
        PBDATE is the variable from input database file in YYMMDD Char
        DTEMP_DOB_ISO     S               D   DATFMT(*ISO)
        Dtemp_DOB_date    S              8A               
        Dtemp_DOB_date1   S              8  0             
        Dtemp_BIRTH_DT    DS                              
        Dt_year                          2                
        Dt_slash3                        1    inz('/')    
        Dt_month                         2                
        Dt_slash4                        1    inz('/')    
        Dt_day                           2
        Similarly i have another date Withdrwan date (Wdate), I converted that date also similarly, now I want to find the Age of the students when they withdraw from the School, we have with drawn date (WWDATE) and Birtth date (PBDATE), now I want some date functions to find the age of students, so that I can eliminate the students whose age is less than 16 years from my output file.
        Can someone throw some light on this date conversion for me in calculating the Age.

        Note: My AS/400 releae version is 'V4R4M0', so that latest date conversion functions will not work in our system.

        Anil.

        Comment


        • #5
          Re: Date Conversion

          So lets say you have the dates stored in numeric fields in CCYYMMDD format.

          Student 1 Birthdate = 19900115
          Student 2 Birthdate = 19950627

          Both students withdraw from classes on 20070709

          Now take 16 years from the withdraw date

          20070709
          - 160000
          ---------------
          19910709

          If 19910709 < birthdate then student < 16 years old

          Student 1 > 16 years old at withdraw
          Student 2 < 16 years old at withdraw

          Hope that helps
          Goodbye

          Comment


          • #6
            Re: Date Conversion

            Originally posted by medam.anil View Post
            I have my two dates in the input file in the format of YYMMDD in char format, now I converted the dates to CCYYMMDD
            ...

            Similarly i have another date Withdrawn date (Wdate), I converted that date also similarly, now I want to find the Age of the students when they withdraw from the School, we have with drawn date (WWDATE) and Birth date (PBDATE), now I want some date functions to find the age of students, so that I can eliminate the students whose age is less than 16 years from my output file.
            Can someone throw some light on this date conversion for me in calculating the Age.

            Note: My AS/400 release version is 'V4R4M0', so that latest date conversion functions will not work in our system.

            Anil.
            Even for V4R4 you're doing way more work than is needed. For example none of the %SUBST stuff is needed as far as I can see. If PBDate and WWDate are character fields of 6A then all you need to do is:

            Code:
                 d WWDate          s              6a
                 d PBDate          s              6a
            
                 d workWWDate      s               D
                 d workPBDate      s               D
            
                 d age             s              5p 0
            
                 C     *YMD0         Move      WWDate        workWWDate
                 C     *YMD0         Move      PBDate        workPBDate
                 C     workPBDate    SubDur    workWWDate    age:*Y
                 C                   If        age > 15
            Of course you won't need the field definitions for WWDate and PBDate but I included them here for completeness.

            If you were using V5R1 or later it would all be done in one line with no data definitions needed at all:

            Code:
              If %Diff( %Date(PBDate: *YMD0) : %Date(WWDate: *YMD0) : *Y ) > 15;

            Comment

            Working...
            X