+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 20

Thread: Moving numeric field to date data type field.

  1. #1
    Guest.Visitor Guest

    Default Moving numeric field to date data type field.

    I am using some older files that store date in a MMDDYY format as a six digit packed field. I've been trying to use these dates with RPG IV and would like to find a way to move the numeric date into a date field that is defined on a "D" spec. One way I have accomplished this is to move the field to a character field and then parse the field and concatenate in the field seperaters with the result of MM/DD/YY. This can then be moved to the date field. This seems like a lot of extra code to do this. Can you do this with simple move?

  2. #2

    Default Moving numeric field to date data type field.

    Easy as pie, Jim. MDY is the 6-digit date in MMDDYY, and Date is a date field. The following move does the trick:
    C *MDY MOVE MDY Date 
    I love RPGIV's date handling. Joe src="//www.zappie.net/java/_derived/index.htm_cmp_zero110_vbtn_p.gif" width="140" height="60" border="0" alt="Java400.net - Java/400 Freeware" align="middle"> Java400.Net - where the AS/400 speaks Java with an RPG accent Home of PBD2.0, the color=red>FREE Java/400 Client/Server color=blue>Revitalization Toolkit

  3. #3
    Guest.Visitor Guest

    Default Moving numeric field to date data type field.

    If the numeric date field Does Not have separators use the following:
     C *MDY0 move Date6 ISODate 
    Jerry Hensley Peerless Chain

  4. #4

    Default Moving numeric field to date data type field.

    Jerry, I don't believe that the *MDY0 move is necessary, and that *MDY will suffice. TTBOMK *MDY describes the field that is to be moved in numeric form. Anything in numeric form will not have separators. If the field was character based, then *MDY0 would be necessary. It does not matter what format the receiving date data type uses. Dave

  5. #5
    J.Panzenhagen Guest

    Default Moving numeric field to date data type field.

    I think that if the field were character, it would not require *MDY0 because it is not possible to have that format and separators in a 6 byte field.

  6. #6
    Guest.Visitor Guest

    Default Moving numeric field to date data type field.

    I think you do need *MDY0 on the move instead of *MDY from a 6a field. Otherwise you will get a compile error saying that the 6a field is not large enough to hold the separators. Chris

  7. #7
    Guest.Visitor Guest

    Default Moving numeric field to date data type field.

    David, You are correct. I should have said if the date is defined as alpha use the *MDY0. Sometimes I get ahead of myself. Thanks, Jerry Hensley Peerless Chain

  8. #8

    Default Moving numeric field to date data type field.

    Jerry (and everybody else): The four typical formats we use, MMDDYY, YYMMDD, MMDDCCYY and CCYYMMDD each have their own version of the data attributes that are used in the factor 1 field: *MDY = MMDDYY *USA = MMDDCCYY *YMD = YYDDMM *ISO = CCYYMMDD These attributes are valid for numeric field or character fields, with the stipulation that character fields require separators. To convert character fields with no separators, you can use the corresponding data attribute with a '0' (that's the digit zero) on the end. Here's a program that shows all the permutations:
    d dmmddyy S D d dmmddccyy S D d dyymmdd S D d dccyymmdd S D C* C move '01/01/81' cmmddyys 8 C move '01/01/1982' cmmddccyys 10 C move '83/01/01' cyymmdds 8 C move '1984-01-01' cccyymmdds 10 C* C *MDY move cmmddyys dmmddyy C *USA move cmmddccyys dmmddccyy C *YMD move cyymmdds dyymmdd C *ISO move cccyymmdds dccyymmdd C* C move '020281' cmmddyy 6 C move '02021982' cmmddccyy 8 C move '830202' cyymmdd 6 C move '19840202' cccyymmdd 8 C* C *MDY0 move cmmddyy dmmddyy C *USA0 move cmmddccyy dmmddccyy C *YMD0 move cyymmdd dyymmdd C *ISO0 move cccyymmdd dccyymmdd C* C move 030381 nmmddyy 6 0 C move 03031982 nmmddccyy 8 0 C move 830303 nyymmdd 6 0 C move 19840303 nccyymmdd 8 0 C* C *MDY move nmmddyy dmmddyy C *USA move nmmddccyy dmmddccyy C *YMD move nyymmdd dyymmdd C *ISO move nccyymmdd dccyymmdd C* c move *on *inlr 
    The character fields with separators are two positions longer than the character fields without separators (which makes sense). Note that the *ISO format defaults to a separator of '-', while the rest default to '/' (that default, I believe, is a job setting, but I'm not sure). There are quite a few other permutations of the data attributes that allow you to specify a different separator, support Julian dates and 7-digit dates (leading century digit), support time fields and such. For more information than you'll probably ever need on movement between dates and non-dates (and other moves), click href="http://publib.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/QB3AGZ03/4.4.59#HDRZZM OVE">here. Joe src="//www.zappie.net/java/_derived/index.htm_cmp_zero110_vbtn_p.gif" width="140" height="60" border="0" alt="Java400.net - Java/400 Freeware" align="middle"> Java400.Net - where the AS/400 speaks Java with an RPG accent Home of PBD2.0, the color=red>FREE Java/400 Client/Server color=blue>Revitalization Toolkit

  9. #9
    Guest.Visitor Guest

    Default Moving numeric field to date data type field.

    Note that the *ISO format defaults to a separator of '-', while the rest default to '/' (that default, I believe, is a job setting, but I'm not sure). The default separators aren't variable. The default separator is fixed for each format: href="http://publib.boulder.ibm.com:80/cgi-bin/bookmgr/BOOKS/QB3AGZ03/2.3.4#TBLD TFMTX2">http://publib.boulder.ibm.com:80/cgi-bin/bookmgr/BOOKS/QB3AGZ03/2.3.4#TB LDTFMTX2. Barbara Morris

  10. #10

    Default Moving numeric field to date data type field.

    An interesting point here... rather than specifying the format on the move, you can specify the format when defining the DATE field (including the ability to override the separator). Doing that, you can then just move your character or numberic data in and out of the date field without specifying an attribute in factor 1. Later, the dates can be used as normal for calculations. To "convert" the format, you can move one date to another, then move the second date field to your output field. Here's a second program that illustrates these features:
    d ddefault S D DATFMT(*MDY) d dslashes S D DATFMT(*MDY/) d dcommas S D DATFMT(*MDY,) d ddots S D DATFMT(*MDY.) d diso S D DATFMT(*ISO) C* C move '01/01/82' cslashes 8 C move '01,01,83' ccommas 8 C move '01.01.84' cdots 8 C* c move cslashes ddefault c move cslashes dslashes c move ccommas dcommas c move cdots ddots C* c ddefault subdur dcommas days:*d 3 0 C* c move ddots diso c move diso ciso 10 C* c move *on *inlr 
    At the end of this, days is -365, and ciso is "1984-01-01". Pretty cool stuff. Joe src="//www.zappie.net/java/_derived/index.htm_cmp_zero110_vbtn_p.gif" width="140" height="60" border="0" alt="Java400.net - Java/400 Freeware" align="middle"> Java400.Net - where the AS/400 speaks Java with an RPG accent Home of PBD2.0, the color=red>FREE Java/400 Client/Server color=blue>Revitalization Toolkit

+ Reply to Thread
Page 1 of 2 1 2 LastLast

Similar Threads

  1. Problem with Date Type field and field Reference File
    By David Abramowitz in forum General
    Replies: 2
    Last Post: 07-27-2006, 10:32 AM
  2. DATE field type in SQL
    By DougCMH in forum SQL
    Replies: 4
    Last Post: 08-04-2004, 11:33 AM
  3. Moving a date defined field to a numeric field using free format
    By buck.calabro@commsoft.net in forum General
    Replies: 2
    Last Post: 05-25-2004, 02:00 AM
  4. Replies: 2
    Last Post: 05-09-2002, 01:43 PM
  5. Converting a numeric field into a date field
    By David Abramowitz in forum RPG
    Replies: 3
    Last Post: 02-12-2002, 07:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts