Increment a date

Posted by hermes on 31-Aug-2015 09:26

I need to add 2 days to a date. I know I have to adjust for a leap year and if the day happens to be greater than or equal to the 28th and for some months having 30 or 31 days. I am stuck at the beginning. I try to create the first  condition to check for the actual day. If I assign before the if loop  the first part works. But using the assign in the if/else loop fails. What am I doing wrong... if you have other ideas on the month or 30 vs 31 days I would appreciate that. Thanks.

DO:
 
  ASSIGN FRAME fmain txtName.
 
  DEF VARIABLE v_date_increment AS CHAR.
 
 /* ASSIGN v_date_increment = STRING(DAY(TODAY),"99"). */
 
 
 IF DAY(TODAY) LE 28 THEN
 ASSIGN v_date_increment = STRING(DAY(TODAY) + 2,"99").
  MESSAGE "Hello, " v_date_increment "!" VIEW-AS ALERT-BOX.
   
  ELSE
  ASSIGN v_date_increment = STRING(DAY(TODAY),"99").
   MESSAGE "Hello, " txtName "!" VIEW-AS ALERT-BOX.

    
    
 
  txtName = "".
 
  DISPLAY txtName WITH FRAME fmain.
 
  APPLY "ENTRY" TO txtName.
 
END.

All Replies

Posted by Brian K. Maher on 31-Aug-2015 09:30

Wby don't you simply do...
 
MyDateVariable = MyDateVariable + 2.
 

Posted by hermes on 31-Aug-2015 09:36

I am doing that in STRING(DAY(TODAY) + 2... but there will be conditions where the day is not valid (ie. day is the 31st, it is february 27th...)

Posted by Brian K. Maher on 31-Aug-2015 09:38

DEFINE VARIABLE MyDateVariable AS DATE NO-UNDO.

MyDateVariable = TODAY + 2.

DISPLAY "Current Date: " TODAY "Two Days From Now: " MyDateVariable.


Posted by Brian K. Maher on 31-Aug-2015 09:39

hermes, you are incorrect.  Just increment the date variable itself, not the components (month, day, year).  This is one of the things that the ABL makes very, very simple.  You are thinking "old style" and making it much harder than it needs to be.

Posted by ssouthwe on 31-Aug-2015 09:43

STRING(DAY(TODAY + 2))
 
Steve Southwell
Senior Consultant
progress-bravepoint-logo2
www.bravepoint.com
Direct: 469-322-4265
 
[collapse]
From: hermes [mailto:bounce-hermes@community.progress.com]
Sent: Monday, August 31, 2015 9:38 AM
To: TU.OE.Development@community.progress.com
Subject: RE: [Technical Users - OE Development] Increment a date
 
Reply by hermes

I am doing that in STRING(DAY(TODAY) + 2... but there will be conditions where the day is not valid (ie. day is the 31st, it is february 27th...)

Stop receiving emails on this subject.

Flag this post as spam/abuse.

[/collapse]

Posted by peggycole on 31-Aug-2015 09:49

You can use the add-interval function where you even can specify the "unit" ('days', 'months', 'weeks', ...):

MESSAGE add-interval(TODAY, 2, "days")

   VIEW-AS ALERT-BOX INFO BUTTONS OK.

Posted by hermes on 31-Aug-2015 10:02

Brian,

Yes on it's face that is correct but I was trying another way because there is formatting that needs to be done. The date should appear as 20150831 for today and not as 08/31/2015.

Posted by gdb390 on 31-Aug-2015 10:08

use the add-interval and do the formatting afterwards

assign

 vdtDate = add-interval(TODAY, 2, "days").

assign vcFormattedDate = string(year(vdtDate), "9999":u) + string(month(vdtDate), "99":u) + string(day(vdtDate), "99":u).

Posted by peggycole on 31-Aug-2015 10:09

you can always re-format your date after the calculation:

define variable vdtDummy as date no-undo.

vdtDummy = add-interval(TODAY, 2, "days").

message string(year(vdtDummy), "9999") + string(month(vdtDummy), "99") + string(day(vdtDummy), "99")

view-as alert-box info.

Posted by TheMadDBA on 31-Aug-2015 10:12

All you have to is add the number of days as suggested... which always gives you a proper date regardless of leap year or switching months.

Then format the resulting variable by parsing the year,month and day...


DEFINE VARIABLE myDate AS DATE NO-UNDO. ASSIGN myDate = TODAY + 2. MESSAGE STRING(YEAR(myDate),"9999") + STRING(MONTH(myDate),"99") + STRING(DAY(myDate),"99") VIEW-AS ALERT-BOX.



Posted by Brian K. Maher on 31-Aug-2015 10:15

Do the formatting outside of the incrementing.  It will be much easier.
 

Posted by Stefan Drissen on 31-Aug-2015 10:23

And instead of stringing date parts together, use the built-in iso-date function:

message replace( iso-date( today ), "-", "" ).


Posted by hermes on 31-Aug-2015 10:45

Great, Thanks peggycole that works great... Thanks everyone for your input.

This thread is closed