WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: mjwillyone on September 25, 2021, 09:15:58 AM

Title: Testing for the second to last business day of a month
Post by: mjwillyone 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
Title: Re: Testing for the second to last business day of a month
Post by: kdmoyers 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
Title: Re: Testing for the second to last business day of a month
Post by: JTaylor 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
Title: Re: Testing for the second to last business day of a month
Post by: mjwillyone 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!
Title: Re: Testing for the second to last business day of a month
Post by: jmburton2001 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) Select
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!  ;)