Page 1 of 1

Schedule on "last day of month"

PostPosted: Wed Feb 14, 2024 1:54 am
by MarcoGT
Hi all,

is there a way to set a schedule for last day of month? I know I can set the exact day (30,31) but every month is different and I need the schedule on the last day (in February on the 28th, 9th this year) :D

Thanks
Marco

Re: Schedule on "last day of month"

PostPosted: Wed Feb 14, 2024 6:01 am
by DaveL17
Not with the schedule date options, but it is possible to do it. There's an elegant approach in this other thread along with a couple other suggestions. I think this one is best.

Set your condition on a schedule run every day to fire if Python returns true. Check to see if tomorrow is in a different Month than today:

Code: Select all
import datetime

current_date = datetime.datetime.today()
nextday_date = datetime.datetime.today() + datetime.timedelta(days=1)
if (current_date.month != nextday_date.month):
    return True
else:
    return False


Re: Schedule on "last day of month"

PostPosted: Wed Feb 14, 2024 8:05 am
by MarcoGT
Thanks a lot, but getting an error:

Code: Select all
return True
    ^^^^^^^^^^^
SyntaxError: 'return' outside function


Is this anything new in 3.11?

Re: Schedule on "last day of month"

PostPosted: Wed Feb 14, 2024 9:24 am
by DaveL17
Did you paste the entire code block as it appears? I'm not seeing that error. This isn't anything new with Python 3.11.

What version of Indigo are you using?

Re: Schedule on "last day of month"

PostPosted: Wed Feb 14, 2024 9:30 am
by FlyingDiver
Also, that code does NOT go into an action for the schedule. It goes into the Conditions tab.

Re: Schedule on "last day of month"

PostPosted: Wed Feb 14, 2024 9:43 am
by DaveL17
Good call Joe. I hadn't considered that as a possibility -- but with that -- the error make more sense.