Home
Name Modified Size InfoDownloads / Week
CHGDTETME.CMD 2021-03-25 1.9 kB
CHGDTETMEH.PNLGRP 2021-03-25 6.1 kB
LICENSE 2021-03-25 1.1 kB
CHGDTETMEV.RPGLE 2021-03-25 8.8 kB
CHGDTETMEP.RPGLE 2021-03-25 17.8 kB
README 2021-03-25 3.2 kB
Totals: 6 Items   39.0 kB 1
**************************************************************************************************************************

DESCRIPTION
‾‾‾‾‾‾‾‾‾‾‾

The Change Date Time (CHGDTETME) command adds or subtracts a duration to a timestamp and returns a timestamp result.

The base timestamp must be a valid timestamp in YYYY-MM-DD-HH.MM.SS format. Special value *CURRENT can be specified, 
the current system date and time will be used.

The Duration to be applied to the base timestamp must be in YYYY-MM-DD-HH.MM.SS format. Each segment can range from 
all 0's to all 9's. Special values can be specified: *DAY (1 day), *WEEK (7 days), *MONTH (1 month), and *YEAR (1 year). 

The result date must be between January 1, 0001 and January 1, 10000. Dates outside this range result in an error 
message. The returned timestamp will be in YYYY-MM-DD-HH.MM.SS format. 


The command makes use of two interesting and very powerful functions, _INCTS and _DECTS, to increment and decrement 
timestamps by a duration. In RPG each segment would be handled seperately: %seconds, %hours, %months, etc. The MI 
functions handle the complete duration as a whole. Additionally they support multiple calendar systems. 


The command was developed and tested on a 7.4 machine. 



TO CREATE
‾‾‾‾‾‾‾‾‾

Load the source to a location of your choice and compile:


CRTBNDRPG  CHGDTETMEP  TEXT('CHGDTETME Command Processing Program')

CRTBNDRPG  CHGDTETMEV  TEXT('CHGDTETME Command Validation Program')

CRTPNLGRP  CHGDTETMEH  TEXT('CHGDTETME Command Help Text')

CRTCMD  CMD(CHGDTETME)  PGM(CHGDTETMEP)  VLDCKR(CHGDTETMEV)  ALLOW(*BPGM *IPGM)  HLPPNLGRP(CHGDTETMEH) HLPID(CHGDTETME)    



USAGE
‾‾‾‾‾

    DCL  &OLDTMESTMP  *CHAR  19 
    DCL  &DURATION    *CHAR  19 

    DCL  &RESULT *CHAR 19
    DCL    &DATE   *CHAR 10  STG(*DEFINED)  DEFVAR(&RESULT  1)
    DCL      &YEAR   *CHAR 4 STG(*DEFINED)  DEFVAR(&RESULT  1)
    DCL      &MONTH  *CHAR 2 STG(*DEFINED)  DEFVAR(&RESULT  6)
    DCL      &DAY    *CHAR 2 STG(*DEFINED)  DEFVAR(&RESULT  9)
    DCL    &TIME   *CHAR  8  STG(*DEFINED)  DEFVAR(&RESULT 12)
    DCL      &HOUR   *CHAR 2 STG(*DEFINED)  DEFVAR(&RESULT 12)
    DCL      &MINUTE *CHAR 2 STG(*DEFINED)  DEFVAR(&RESULT 15)
    DCL      &SECOND *CHAR 2 STG(*DEFINED)  DEFVAR(&RESULT 18)


    CHGDTETME  DTETME(*CURRENT)  DURATION(*SUB *DAY)  RTNVAL(&RESULT)   /* get yesterday's date */
    CHGDTETME  DTETME(*CURRENT)  DURATION(*ADD *WEEK)  RTNVAL(&RESULT)  /* get the date a week from now */
    CHGDTETME  DTETME(*CURRENT)  DURATION(*SUB *YEAR)  RTNVAL(&RESULT)  /* get the date a year ago */
             
    /* specify a particular base datetime and duration */    
    CHGDTETME  DTETME('2021-03-24-01.30.00')  DURATION(*SUB '0000-00-00-02.00.00)  RTNVAL(&RESULT) 
    /* subtracts two hours from 1:30 March 24, 2021 and returns 23:30 March 23, 2021 */



    /* If it's morning get yesterday's date */
    RTVSYSVAL QHOUR  &HOUR
    IF COND((&HOUR *LT 12) THEN(DO)
      CHGDTETME DTETME(*CURRENT) DURATION(*SUB *DAY) RTNVAL(&RESULT)
    ENDDO

**************************************************************************************************************************

Source: README, updated 2021-03-25