viewpoint-particle

Author Topic: Testing for the second to last business day of a month  (Read 187 times)

mjwillyone

  • Newbie
  • *
  • Posts: 48
Testing for the second to last business day of a month
« on: September 25, 2021, 09:15:58 am »
First off I want to say a HUGE thank you for the patience and expertise given me by those who have replied to my recent and frequent posts.  I am working on a huge in-house automation project and could not have progressed this far this soon without this forum and the kind people in it.  Thank you!!

In this post I am wanting to test for the second to the last business day of the month. If it is NOT this date, I will use the goto command, execute a few lines, and close the script.  If it IS the second to the last business day, I want to execute the majority of the script.

How can I test for that day?

Thank you very much!
Mike

kdmoyers

  • Sr. Member
  • ****
  • Posts: 434
Re: Testing for the second to last business day of a month
« Reply #1 on: September 25, 2021, 09:43:34 am »
well, I wont code it up for you, but if I did,
(bugs included for free)

z = 0
x = last day of month
loop
   if x is a weekday
       z = z + 1
       if z == 2 then break
   endif
   x = subtract one day from x
endloop

x is your day! you can test if getdate() is equal to that.

FYI, integer day of week is (TimeJulianDay(x) + 5) mod 7
The mind is everything; What you think, you become.

JTaylor

  • Pundit
  • *****
  • Posts: 1743
    • Data & Stuff Inc.
Re: Testing for the second to last business day of a month
« Reply #2 on: September 25, 2021, 09:51:30 am »
You beat me to it Kirby :)

We already did all the hard work for you on the previous question for Last Day of Month.   Combine that with TimeDayofWeek() and you should be able to figure it out.

Jim

mjwillyone

  • Newbie
  • *
  • Posts: 48
Re: Testing for the second to last business day of a month
« Reply #3 on: September 25, 2021, 11:45:17 am »
Thanks to both of you.  The last day of month routine was a great success.  That automated routine works great and totally does what a bookkeeper once did but outside of business hours!

jmburton2001

  • Full Member
  • ***
  • Posts: 120
Re: Testing for the second to last business day of a month
« Reply #4 on: September 27, 2021, 06:00:28 am »
Here's a little trick I use in these scenarios.

If I'm trying to test for a particular variable that may occur at a different time or on a differently configured machine, I'll drop a line in my script so I can manually insert the variable I want to test for. Then when I'm done testing I comment or delete the line.

In Kirby's example I'd insert a line just after "x = last day of month"

Code: Winbatch
z = 0
x = last day of month
x = AskLine ("New Last Day", "Change Date", x,0) ; Then comment or delete when finished testing
loop
   if x is a weekday
       z = z + 1
       if z == 2 then break
   endif
   x = subtract one day from x
endloop
 

For me it saves a boatload of time when I'm testing various scenarios and I've used it to test multiple variables at once.

Standard disclaimer - This may or may not be worth two cents and YMMV;)