Jump to content
Macro Express Forums

Add Days To Date, But Only Business Days?


jhoover

Recommended Posts

First, I guess I should say that I've been using KeyText as my macro editor for a while now, but I'm having all kinds of problems since upgrading to XP, so I figured I'd give MacroExpress a try. The way that I do this in KeyText is to use the command {down {Date+4r "d"}}. Here's where I am with the ME code:

<DT:dT:01:3:{F00004}{P00000}{P00000}{P00000}><TMVAR2:05:01:01:000:000:><REP3:05:000001:000001:0001:0:01:><TEXTTYPE:<DOWN ARROW>><ENDREP><REP3:01:000001:000001:00006:0:01:><TEXTTYPE:<TAB>><ENDREP><DD{NF005}{P000}01><TMVAR2:05:01:01:000:000:><REP3:05:000001:000001:0001:0:01:><TEXTTYPE:<DOWN ARROW>><ENDREP>

 

Is there a way, when manipulating the date, to add days, but only business days (Monday thru Friday)?

 

Basically, I have a form that has a "due date" on it. It should always be 5 business days (including today as day 1) from today. I want to have the date + 5 days pass to a variable, convert the variable to numeric, and use it to run a loop to push the down arrow "date+5" times.

 

I am able to do this no problem with just 5 days, but for example, today is Wednesday, so 5 business days from today would be next Tues, the 26th, but instead it will give me next Sunday, the 24th. :wacko: This won't work since it would basically give only 3 days to work on it.

 

Anyone have any idea how to do this?

 

Thanks,

John Hoover

john.hoover@us.ing.com

Link to comment
Share on other sites

Hi John,

Welcome, and good luck with ME3!

If you are only looking at Excluding weekends, (can't pick public holidays!), then only Mondays as today will not be affected; so add 6,except if today is a Monday (do you need to set this on a Sun or sat as well? (2 less);

Date/Time: Save "d" into %T1%

Variable Modify String: Convert %T1% to integer %N1%

Date/Time: Save "ddd" into %T1%

Text Box Display:

If Variable %T1% = "Mon"

  OR

If Variable %T1% = "Sun"

  OR

If Variable %T1% = "Sat"

  Variable Modify Integer: %N1% = %N1% - 2

End If

Repeat with Variable using %N1%

  Text Type: <DOWN ARROW>

Repeat End

Text Box Display:

<DT:dT:01:3:{F00006}{P00000}{P00000}{P00000}><TMVAR2:05:01:01:000:000:><DT:dddT:01:3:{F00000}{P00000}{P00000}{P00000}><TBOX4:T:1:CenterCenter000278000200:000:Date = %N1% days ahead
T1-%T1%><IFVAR2:1:01:1:Mon><OR><IFVAR2:1:01:1:Sun><OR><IFVAR2:1:01:1:Sat><NMVAR:02:01:1:0000001:2:0000002><ENDIF><REP3:05:000001:000001:0001:0:01:><TEXTTYPE:<DOWN ARROW>><ENDREP><TBOX4:T:1:CenterCenter000278000200:000:Date = %N1% days ahead>

Best, Randall

Link to comment
Share on other sites

Thanks for the welcome and the script. I thought about doing something like this but wasn't sure how to implement it.

I do have a couple of problems though. If the Date + 6 winds up on the first of the month, and it also happens to be one of the days from the IF statements, it winds up trying to add "-1" days and freaks out a bit. This happens next monday, the 25th.

I also use a similar chunk of code to put in the month using the down arrow. I guess I should do something like IF %N1% > 25 THEN %N2% = %N2% + 1 Where N1 is the date, and N2 is the number of the month. Though this would pose problems because some months have 31 days and if the conditions are right, I'd end up scheduling a month + 5 business days, and because of February having only 28, I'd end up a month behind since it wouldn't start changing over the month on the 23rd. I suppose there could be an IF statement for Feb, an IF statement for months with 30 days, and an IF statement for months that have 31.

Just seems needlessly complex when all it took was {down {date +4r "d"}} in KeyText. Granted, ME is FAR more advanced than KT ever thought about being, and the added flexibility is nice.

 

Thanks for your help, I'll see if I can work out some solutions.

Link to comment
Share on other sites

Hi,

Yes, sorry I messed it up. You should not have to use anymore "if"s, though.

I have trouble understanding your date tabbing setup; i see now you are in "date" and "month" dropdon. up/down" lists?

Calculate just %N1% as the number of days ahead, then use that in the date formula to retrieve the proper month (%N2%);and day; redefine %N1%... OK? Randall

// First time, find %N1%= 4 days or 6 to add

Variable Set Integer %N1% to 6

Date/Time: Save "ddd" into %T1%

If Variable %T1% = "Mon"

  Variable Modify Integer: %N1% = %N1% - 2

End If

// Second time, time, use %N1% ; retrieve %N2%, will be correct month, and %N1% date of correct month

Date/Time: Save "M" into %T1%

Variable Modify String: Convert %T1% to integer %N2%

Date/Time: Save "d" into %T1%

Variable Modify String: Convert %T1% to integer %N1%

Text Box Display:

<REM2:First time, use today's date then add find %N1%= 4 days or 6 to add><IVAR2:01:01:6><DT:dddT:01:3:{F00000}{P00000}{P00000}{P00000}><IFVAR2:1:01:1:Mon><NMVAR:02:01:1:0000001:2:0000002><ENDIF><REM2:Second time, time, use %N1% ; retrieve %N2%, will be correct month, and %N1% date of correct month><DT:MT:01:3:{F0%N1%}{P00000}{P00000}{P00000}><TMVAR2:05:01:02:000:000:><DT:dT:01:3:{F0%N1%}{P00000}{P00000}{P00000}><TMVAR2:05:01:01:000:000:><TBOX4:T:1:CenterCenter000278000200:000:Date = %N1% of

Month then; %N2%>

(Not sure about Sat and Sun?)
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...