[Resolved] Expression to display 2nd Friday in May and Last Saturday in September

expression

#1

1) Give a description of the problem
I am trying to figure out a way to write two expressions that determines.

  1. The second Friday in May as a date only (with no time)
  2. The last Saturday in September as a date only (with no time)

Part 1 always appears as the “Second” Friday in May
For example:
2021 - it would appear as Fri. May 14, 2021
2022 – it would appear as Fri. May 13, 2022
2023 – It would appear as Fri. May 12, 2023
Etc., etc., etc.

Part 2 always appears as the “Last” Saturday in September
For example:
2021 - it would appear as Sat. Sep 25. 2021
2022 – it would appear as Sat. Sep 24, 2022
2023 – It would appear as Sat. Sep 30, 2023
Etc., etc., etc.

2) What is the expected behaviour?
My piston (see below) only runs between the second Friday in May and last Saturday in September. This is for the lighting of our deck season. (Note: I realize the dates in the piston are not correct they are only presented as an example)

**3) What is happening/not happening? **
It is working as currently written (See Below) however it must be manually updating each year. I was looking for more of a dynamic method. Instead of keying in hard dates I was looking for two expressions that would replace the dates.

**4) Post a Green Snapshot of the piston![image|45x37]

5) Attach logs after turning logging level to Full
N/A


#3

Thanks for the response @jkp

Unless I really am misunderstanding the expressions you have provide:

addDays(date("3/21/"+$year),1)

I believe what this does is add a day to the date provided in the year it was executed.

For example,
in 2021 it would appear as Mon. Mar 22, 2021,
in 2022 it would appear as Tue Mar 22, 2022.
In 2023 it would appear as Wed. Mar 22, 2023.
Etc., etc., etc.

What I am looking for is a bit more complicated

Part 1 always appears as the “Second” Friday in May
For example:
2021 - it would appear as Fri. May 14, 2021
2022 – it would appear as Fri. May 13, 2022
2023 – It would appear as Fri. May 12, 2023
Etc., etc., etc.

Part 2 always appears as the “Last” Saturday in September
For example:
2021 - it would appear as Sat. Sep 25. 2021
2022 – it would appear as Sat. Sep 24, 2022
2023 – It would appear as Sat. Sep 30, 2023
Etc., etc., etc.


#4

Try this code, you can probably run it on the first day of the month or something and store the dates somewhere… fun brain exercise :smiley:

Just edit it to fit in your code.

9/21/2021, 9:49:13 AM +67ms
+762ms	║5/14/2021 is 2nd Friday in May
+1668ms	║9/25/2021 is last Saturday in September


#5

Here is another solution. More variables but no loop. Edit to use as desired:

9/21/2021, 12:36:22 PM +315ms
+1ms	╔Received event [Las Vegas].test = 1632252982312 with a delay of 3ms
+305ms	║Finding day of week 5
+305ms	║Looking in month 9
+305ms	║In year 2021
+305ms	║Finding Week 2
+305ms	║Offset from first of month is 9
+327ms	║Output date is 09/10/2021
+333ms	╚Event processed successfully (333ms)


#6

Thank you both @eibyer and @guxdude, you both provided unique approaches:
Second Friday, Last Sunday and Find a Day