Skip to main content
Level 2
May 1, 2024 9:16 AM UTC
Solved

Token for a specific day of the month

Hello,

I have seen quite a few conversations and options regarding the selection of date tokens but I would be interested to have input on what to select or create for the selection of a specific day of the month. What I mean is that I need to select not a date like 1st May but a day, like the fourth Wednesday of the month. 

Would anyone have a suggestion/solution?

Thank you.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
SanfordWhiteman
SanfordWhitemanAccepted solution
User Group Leader
May 2, 2024 6:38 PM UTC

Include the same boilerplate from the top of Velocitip: Find the first Y-day of next month:

 

#set( $defaultTimeZone = $date.getTimeZone().getTimeZone("America/New_York") ) #set( $defaultLocale = $date.getLocale() ) #set( $calNow = $date.getCalendar() ) #set( $ret = $calNow.setTimeZone($defaultTimeZone) ) #set( $calConst = $field.in($calNow) ) #set( $ISO8601DateOnly = "yyyy-MM-dd" ) #set( $ISO8601DateTime = "yyyy-MM-dd'T'HH:mm:ss" ) #set( $ISO8601DateTimeWithSpace = "yyyy-MM-dd HH:mm:ss" ) #set( $ISO8601DateTimeWithMillisUTC = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" ) #set( $ISO8601DateTimeWithMillisTZ = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" )

 

 

Then a slight tweak to that code to find the Xth Y-day of this month:

 

#set( $nth = 4 ) #set( $day = "WEDNESDAY" ) #* NO NEED TO TOUCH BELOW THIS LINE! *# #set( $dayConst = $calConst.get($day) ) #if( $dayConst < 7 ) #set( $nextDayConst = $math.add($dayConst,1) ) #else #set( $nextDayConst = 1 ) #end #set( $thisMonth = $date.getCalendar() ) #set( $ret = $thisMonth.setTimeZone($defaultTimeZone) ) #set( $ret = $thisMonth.set($calConst.DAY_OF_MONTH, 1) ) #set( $ret = $thisMonth.setFirstDayOfWeek($nextDayConst) ) ## the day *after* Y-day #set( $ret = $thisMonth.set($calConst.DAY_OF_WEEK, $dayConst) ) ## Y-day itself #set( $ret = $thisMonth.add($calConst.WEEK_OF_MONTH, $math.sub($nth,1) ) )

 

 

 

And output that day in your chosen format:

 

The ${nth}th/nd ${display.capitalize($day.toLowerCase())} of ${date.format("MMMM yyyy", $thisMonth, $defaultLocale, $defaultTimeZone)} is ${date.format("MM/dd/yyyy", $thisMonth, $defaultLocale, $defaultTimeZone)}

 

 

P.S. In the future, better to avoid the term “select” as that’s kind of vague and sounds like you’re talking about a filter. “Output in an email” is more appropriate.

4 replies

SanfordWhiteman
User Group Leader
User Group Leader
May 1, 2024 4:12 PM UTC

What do you mean by “selection” exactly?

 

Do you mean you’re trying to output the date that’s the 4th Wednesday of the current month in an email, using a specific date format? Or in a landing page? Or something else?

Translate
Level 2
May 2, 2024 1:51 PM UTC

Yes, exactly that. I would like to be able to select the 4th Wednesday, every month.
If possible.... 

Translate
SanfordWhiteman
User Group Leader
SanfordWhitemanUser Group LeaderAccepted solution
User Group Leader
May 2, 2024 6:38 PM UTC

Include the same boilerplate from the top of Velocitip: Find the first Y-day of next month:

 

#set( $defaultTimeZone = $date.getTimeZone().getTimeZone("America/New_York") ) #set( $defaultLocale = $date.getLocale() ) #set( $calNow = $date.getCalendar() ) #set( $ret = $calNow.setTimeZone($defaultTimeZone) ) #set( $calConst = $field.in($calNow) ) #set( $ISO8601DateOnly = "yyyy-MM-dd" ) #set( $ISO8601DateTime = "yyyy-MM-dd'T'HH:mm:ss" ) #set( $ISO8601DateTimeWithSpace = "yyyy-MM-dd HH:mm:ss" ) #set( $ISO8601DateTimeWithMillisUTC = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" ) #set( $ISO8601DateTimeWithMillisTZ = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" )

 

 

Then a slight tweak to that code to find the Xth Y-day of this month:

 

#set( $nth = 4 ) #set( $day = "WEDNESDAY" ) #* NO NEED TO TOUCH BELOW THIS LINE! *# #set( $dayConst = $calConst.get($day) ) #if( $dayConst < 7 ) #set( $nextDayConst = $math.add($dayConst,1) ) #else #set( $nextDayConst = 1 ) #end #set( $thisMonth = $date.getCalendar() ) #set( $ret = $thisMonth.setTimeZone($defaultTimeZone) ) #set( $ret = $thisMonth.set($calConst.DAY_OF_MONTH, 1) ) #set( $ret = $thisMonth.setFirstDayOfWeek($nextDayConst) ) ## the day *after* Y-day #set( $ret = $thisMonth.set($calConst.DAY_OF_WEEK, $dayConst) ) ## Y-day itself #set( $ret = $thisMonth.add($calConst.WEEK_OF_MONTH, $math.sub($nth,1) ) )

 

 

 

And output that day in your chosen format:

 

The ${nth}th/nd ${display.capitalize($day.toLowerCase())} of ${date.format("MMMM yyyy", $thisMonth, $defaultLocale, $defaultTimeZone)} is ${date.format("MM/dd/yyyy", $thisMonth, $defaultLocale, $defaultTimeZone)}

 

 

P.S. In the future, better to avoid the term “select” as that’s kind of vague and sounds like you’re talking about a filter. “Output in an email” is more appropriate.

Translate