Dates Manipulation

Posted by
  • Get detailed date time information:

* Time HH:MM:SS DD MMM YYYY
 CURRENT.TIME = TIMEDATE()
 CURRENT.TIME = CURRENT.TIME[1,2]: ':' : CURRENT.TIME[4,2]: ':' : CURRENT.TIME[7,2]
 * will give a time of "18:51:00" for instance.
  • Date formatting:

CALL DIETER.DATE(DATE.IN,DATE.OUT,’D’)

Example:

ORD.DATE = R.DXO<DX.ORD.TRADE.DATE>
(for instance= '20151106')
ORDER.DATE = ''
IF (ORD.DATE) THEN CALL DIETER.DATE(ORD.DATE,ORDER.DATE,'D')
=> gives ORDER.DATE = '06 NOV 2015'
  • Compute a difference between 2 dates:

CALL CDD(YREGION,START.DATE, END.DATE, DAYS.DIFF)

With DAYS.DIFF set to W for a difference in working days, C for a difference in calendar days. After the call, DAYS.DIFF will contain the days difference. No region (first parameter equals “”) means default region “00”.

Example:

REMAIN.CAL.DAYS = "C"
    START.DATE = TODAY           
    IF START.DATE < EXPIRY.DATE THEN
        CALL CDD('',START.DATE, EXPIRY.DATE, REMAIN.CAL.DAYS)
    END  
=> gives REMAIN.CAL.DAYS = 115

  • Derive a date by adding or subtracting a number of days:

CALL CDT(YREGION,YDATE, YDAYS)

With:
YREGION only necessary when calculating working days
YDATE= YYYYMMDD
YDAYS: number without (= ‘+’) or with ‘+’ or ‘-‘ sign in front and without (= ‘W’) or with ‘W’ (= Working days to be calculated) or ‘C’ (=Calender days to be calculated) at the end.
Definition may be multiple: e.g. ‘+02W03C’ or ‘+10W-3C’

Example:

if TODAY = 20140606
        PROCESS.DATE = TODAY
        DAY.COUNT = "-3W"
        CALL CDT('', PROCESS.DATE, DAY.COUNT)
	
=> gives PROCESS.DATE = 20140603

  •  Check if a day is open or a banking holiday

Example with “date_to_check” which can be the next open day if it’s a banking holiday:

COUNTRY.CODE = ''               
COUNTRY.CODE = R.COMPANY(EB.COM.LOCAL.COUNTRY)
RETURN.CODE  = ""                
CALL WORKING.DAY('',date_to_check;,'','','',COUNTRY.CODE,'','',RETURN.CODE,'')
IF RETURN.CODE = 0 THEN
    (...)
END ELSE
    ADJ.MAT.DATE = date_to_check
    CALL CDT('',ADJ.MAT.DATE,'+1W')
    (...)
END                         

7 comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.