To populate a date variable from something other than a literal string, you have to use the IBM-supplied %date BIF. If used with no parameters, %date will return the current system date.
1 2 3 4 5 6 7 | d myDate s d /free myDate = %date (); // myDate = *the current system date* *inlr = *on ; /end-free |
1 | d myDate8 s 8 0 inz (20040501) |
1 2 3 | /free myDate = %date ( myDate8 ); /end-free |
Now we have a "real" date field populated with the equivalent of “May 1, 2004”, but if our numeric value was in a different format this wouldn't work. In this case we need to inform the %date BIF what the format of the incoming numeric should correspond to:
1 2 3 4 5 6 7 8 9 | d myDate s d d myDate8 s 8 0 inz (05012004) /free myDate = %date ( myDate8 : *USA ); dsply myDate ; *inlr = *on ; /end-free |
So far we've focused on date formats with four-digit years. While ideally we would all use four-digit years all the time, this isn't very realistic, since there are still a lot of six-digit numeric dates floating around out there pretending to be "real" dates. Not to worry, %date can handle these as well, given that you supply the appropriate format name.
1 2 3 4 5 6 7 8 9 | d myDate s d d myDate6 s 6 0 inz (050104) /free myDate = %date ( myDate6 : *MDY ); dsply myDate ; *inlr = *on ; /end-free |
1 2 3 4 5 6 7 8 9 10 11 12 | d myDate s d d myDate6 s 6 0 inz (050104) /free myDate = %date ( myDate6 : *MDY ); dsply myDate ; myDate = %date ( myDate6 : *DMY ); dsply myDate ; myDate = %date ( myDate6 : *YMD ); dsply myDate ; *inlr = *on ; /end-free |
1 2 3 | DSPLY 2004-05-01 DSPLY 2004-01-05 DSPLY 2005-01-04 |
Source: ITjungle by by Joel Cochran Read More ...
Cheat Sheets for Numeric data to Date
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | D @dateA S d D @numA S 6 0 inz (041205) D @numB S 7 0 inz (1041206) D @numC S 8 0 inz (20041207) D @numD S 6 0 inz (120804) D @numE S 8 0 inz (12092004) /free @dateA = %date (@numA:*ymd); // yymmdd to D'ccyy-mm-dd' @dateA = %date (@numB:*cymd); // cyymmdd to D'ccyy-mm-dd' @dateA = %date (@numC:*iso); // ccyymmdd' to D'ccyy-mm-dd' @dateA = %date (@numD:*mdy); // mmddyy to D'ccyy-mm-dd' @dateA = %date (@numE:*usa); // mmddccyy to D'ccyy-mm-dd' /end-free |
No comments:
Post a Comment
NO JUNK, Please try to keep this clean and related to the topic at hand.
Comments are for users to ask questions, collaborate or improve on existing.