RPGLE - Various date examples
H*-----------------------------------------
H* %MSeconds %Seconds, %Minutes, %Hours,
H* %Days, %Months, and %Years.
H* %Date, %Time, and %TimeStamp
H*
H*
H*
H*
H*-----------------------------------------
D*-----------------------------------------
D* Program Info
D*-----------------------------------------
D SDS
D @PGM 001 010
D @PARMS 037 039 0
D @JOB 244 253
D @USER 254 263
D @JOB# 264 269 0
D*
D* Field Definitions.
D*
D ISOdate S D
D USAdate S D DatFmt(*USA)
D XMASDate S D Inz(D'2003-12-25')
D LogonDate S D
D Date_Start S 15
D MonthNames S 12 Dim(12) CtData
D Date_String S 40
*
* Time Stamp
*
DTimeStamp S Z
*
D WorkISO S D
D Month S 2 0
D Day S 2 0
D Year S 4 0
D Decimal8 S 8 0
D LogMonth S 2 0
D LogDay S 2
D LogYear S 4 0
D NextMonth S D
D EndOfMonth S D
*
* Variables for free RPG example + some above
*
D DateIn S D
D FromISO S D
D ToISO S D
D DiffDays S 3 0
D WorkField S 5 0
D Name S 9 Based(NamePtr)
D Name2 S 9
D NamePtr S * Inz(%ADDR(Names))
D Names S 63 Inz('Sunday Monday Tuesday Wedn+
D esdayThursday Friday Saturday ')
D*
D* RPG-defined date formats and separators for Date data type
D*
* 2-Digit Year Formats
* *MDY Month/Day/Year mm/dd/yy 8 09/26/03
* *DMY Day/Month/Year dd/mm/yy 8 26/09/03
* *YMD Year/Month/Day yy/mm/dd 8 03/09/26
* *JUL Julian yy/ddd 6 03/926
C*=====
* 4-Digit Year Formats
* *ISO Int Standards Org yyyy-mm-dd 10 2003-09-26
* *USA IBM USA Standard mm/dd/yyyy 10 09/26/2003
* *EUR IBM European Std dd.mm.yyyy 10 26.09.2003
* *JIS Japan Indst Std yyyy-mm-dd 10 2003-09-26
*
*
C*
*
* Okay first lets get todays date
* For display purposes the date is now
* Friday September 26th 2003
* so date now looks like this 2003-09-26
* because the default date type is *ISO
*
C Eval ISOdate = %Date()
*
* Now that I have the date in a date format
* (*ISO) I can do stuff to it.
* Once I move this date to a decimal 8,0 field
* the date is now in format 20030926
* Not very exciting..yet
*
C Move ISODate Decimal8
*
* Now back to the *ISO date lets add
* 1 month to the date.
* date after will equal 2003-10-26
* %days and % years works the same as %months
*
C Eval WorkISO = ISODate + %Months(1)
*
* Logon date is set equal to today then the month is extracted
* the "*M" is the same as "*Months" LogMonth = 09.
* LogDay = 26.
*
C Eval LogonDate = %Date()
C Extrct LogonDate:*Y LogYear
C Extrct LogonDate:*M LogMonth
C Extrct LogonDate:*D LogDay
*
* Build the date string - Later we will add the day name
*
C Eval Date_String =
C %Trim(MonthNames(LogMonth))
C + %trim('@') + %Trim(LogDay)
C + %trim(',@') + %Char(LogYear)
*
* convert the "@" back to *Blanks
* Date_String = 'September 26, 2003'
*
C '@':' ' Xlate Date_String Date_String
*
* TimeStamp = yyyy-mm-dd-hh.mm.ss.mmmmmm (length 26).
* TimeStamp = '2003-09-26-15.16.26.531000'
*
C Eval TimeStamp = %TimeStamp()
*
* Free Format date stuff By the way Name2 = 'Friday'
*
/Free
DateIn = %Date() ;
ISODate = %Date() ;
ISODate = DateIn ;
Year = %Subdt(ISODate:*Y) ;
Month = %Subdt(ISODate:*M) ;
Day = %Subdt(ISODate:*D) ;
FromISO = ISODate - %YEARS(1) ;
ToISO = ISODate ;
DiffDays = %Diff(ToISO:FromISO:*DAYS) ;
ISODate = DateIn ;
WorkField = %Diff(ISODate:D'1899-12-31':*DAYS);
WorkField = %REM(WorkField:7);
NamePtr = NamePtr + (WorkField * 9);
Name2 = Name;
/End-Free
*
* Build the date string - With The Day Name
* DATE_STRING = 'Friday September 26, 2003 '
*
C Eval Date_String =
C %trim(Name) + %Trim('@@')
C + %trim(MonthNames(LogMonth))
C + %trim('@') + %Trim(LogDay)
C + %trim(',@') + %Char(LogYear)
C Eval Date_String = %Xlate('@':' ':Date_String)
*
* Calculate the last day of the month
* ENDOFMONTH = '2003-09-30'
*
C ISODate AddDur 1:*Months NextMonth
C Extrct NextMonth:*D DiffDays
C NextMonth SubDur DiffDays:*D EndOfMonth
C Eval *INLR = *On
C*----------------------------------------------------
** CTDATA MonthNames
January
February
March
April
May
June
July
August
September
October
November
December
No comments:
Post a Comment