How to Create a Template of a Date Format in a Variable

KM had a glitch moment and it's now working using @tiffle method as well

@noisneil ok, now I'm getting worried and really think this is a conspiracy against me hahaha
You just used the method I shared 5 hours ago...

Well we've kinda been going around in circles, so...

2 Likes

Thanks @Zabobon - but I think the brilliance lies with KM.

The Filter action has many powerful talents but they're not all necessarily obvious!!

1 Like

Ok thanks.
Yeah I was just wondering if in this case having them grouped would behave differently than separate. Almost like the way an IF statement is a group of IF, THEN, you know? :wink:

When you grouped, you just used Engroup > Group?

Exactly.

1 Like

Haha true...
But since I've shared that reply a few times, I thought you guys had seen it and maybe there was something wrong with that approach, because no one seemed to comment on that.

Glad we finally came to a few options. It seems that @tiffle's option also brought some light to other users about this process, which is great!

1 Like

Awesome!!!
Again, thank you so much for taking the time to discuss this and bringing your input. Super valuable! :slight_smile:

1 Like

OK, so this has been done to death -- but that's never stopped me before, so here goes nothing!

If I can restate the problem: You'd like to ensure consistent date/time formatting across many macros by storing the format in a "constant" to be used in the ICUDateTime token.

That means processing a token "inside" a token, which I was having trouble with. Then Google led me to this post from @peternlewis, and a possible solution.

Simply put -- double-encode the "inner variable", then double-decode with filters.

Date Test.kmmacros (3.9 KB)

Summary

I've used different variables to make it easier to follow in the debugger, but it works just as well filtering to "source". I've only made the format string a "constant", which makes this usable with the other ICUDateTime variants -- Peter's post shows how to use variables to set the other parameters needed for those.

It works, it does what OP wanted -- but I don't think this is the best method!

It needs multiple actions in each macro that uses it, which is redundant. Much better to use the trick above in a subroutine -- indeed, a good subroutine using just one parameter would allow you get a date/time slug in any number of formats in any macro with just one action. You could even include the "For", Plus", and "Minus" variants in the same subroutine, adding parameters to suit.

Now there's a project for someone...

2 Likes