String to Date?


#1

I recently set up a piston that behaves differently by checking if today’s date falls in a list of manually entered holiday dates. I’d like to make the population of these holiday dates automated for holidays that aren’t always on the same date, like Memorial Day, Labor Day, and Thanksgiving in the US, but I’m struggling to figure out how.

Example: I can determine today, 11/20, is the 3rd Monday in the 11th month using the following: formatDateTime($now,‘F E M’)

What I can’t seem to sort out is how to reverse engineer a date from that F E M format. How do I get an expression to return the date for the 4th Thursday in November? Is there a way? :thinking:


#2

try date("4th Thursday in November")


#3

I can’t decide if I’m more impressed with webCoRE for having that built in, or more embarrassed I didn’t try that. I had no idea you could write in plain text like that… I kept trying to put in various date structures and never though of just going the free-text route!

Edit to add: you got me on that one! It returned a date and I didn’t look closely enough to see it was today, not the 23rd!


#4

so it just returns today?


#5

Yeah, no matter what you put in there. I tried your string of text, then “Thanksgiving” and thought I was really onto something. Then “Valentine’s Day” also returned 11/20/2017 and I realized what was happening.


#6

too bad.

can you save the date associated with the ‘F E M’ value as well?


#7

Not that I can find. All I can do with the ‘F E M’ is tell me a given date ($now or a manually entered date) is the Nth occurrence of a given weekday in a month.

I haven’t been able to come up with a way to have the output be a date, or a date compromised of the ‘F E M’ parameters.


#8

sorry, wasnt clear.

formatDateTime($now,‘F E M’)

could you save $now to Date variable and instead of reverse engineering just use the date variable as needed?


#9

I could, but in this instance it wouldn’t net me what I’m trying to do. What I looking to do was for an expression to generate a date for me - in this case Thanksgiving Day in the US, by generating a date for the 4th Thursday of November.

The $now was just to understand how the ‘F E M’ format worked and what it could tell me. In reality for what I’m trying to do, ‘$now’ is an unknown and I want a function to fill in that blank for me.

So for example, if I put in date(first Monday in September), it’d spit out 9/4 for our Labor Day holiday this year.

I’m probably doing a poor job explaining it and muddied the waters further by throwing in the $now variable on my first post. Sorry about that.


#10

got it. no worries.

are you looking to get the holiday dates? if so, check this:

just to state the obvious, :smiley: with known holiday dates from that URL, you could find each dates ‘F E M’ format and check that against an unknown ‘F E M’ value.


#11

I’ll have to check that out, thanks! My end game is just to get holiday dates without typing them in manually each year, looks like that could be the ticket!