Progress 4GL - Define variable month/year

2.6k views Asked by At

Here's the problem, i need to create a date range on the variable below.

    define variable s_date as character format "99/9999" no-undo.

There is a start_date column in my db (format "99/99/9999"(dd/mm/yyyy)) the date when a customer sales order was entered.

What i need to do is set the variable to create the date range, search and display the results of every sales order of the defined month and year.

PS: I 'm using a form , so the user can define the range of the month and year.

1

There are 1 answers

0
Jensd On

Here's something to get you started. You will have to look into converting it to fit your form.

If you're on an older release that haven't got the ADD-INTERVAL function you can use the DATE function and add +1 to the month instead (just remember that if the month is December (12) you're going to have to increase the year instead and set the month to 1).

DEFINE VARIABLE cFromDate  AS CHARACTER   NO-UNDO.
DEFINE VARIABLE dtFromDate AS DATE        NO-UNDO LABEL "From".
DEFINE VARIABLE dtTomDate  AS DATE        NO-UNDO LABEL "Tom".


DEFINE VARIABLE iMonth     AS INTEGER     NO-UNDO.
DEFINE VARIABLE iYear      AS INTEGER     NO-UNDO.



UPDATE cFromDate FORMAT "99/9999" NO-ERROR.

IF LENGTH(cFromDate) <> 6 THEN DO:
    MESSAGE "Invalid format" VIEW-AS ALERT-BOX ERROR.
    RETURN ERROR.
END.

ASSIGN
    iMonth = INTEGER(SUBSTRING(cFromDate,1,2)) 
    iYear  = INTEGER(SUBSTRING(cFromDate,3,4)) NO-ERROR.

IF iMonth < 1 OR iMonth > 12 THEN DO:
    MESSAGE "Invalid month" VIEW-AS ALERT-BOX ERROR.
    RETURN ERROR.
END.

IF iYear < 1990 OR iYear > 2020 THEN DO:
    MESSAGE "Invalid year" VIEW-AS ALERT-BOX ERROR.
    RETURN ERROR.
END.

ASSIGN
    dtFromDate = DATE(iMonth, 1, iYear)
    dtTomDate  = ADD-INTERVAL(dtFromDate, 1, "month") - 1.


DISPLAY 
    dtFromDate FORMAT "9999-99-99"
    dtTomDate  FORMAT "9999-99-99".