SOLVED

Token for a specific day of the month

Go to solution
ElisabethQ
Level 1

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.

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Token for a specific day of the month

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.

View solution in original post

4 REPLIES 4
SanfordWhiteman
Level 10 - Community Moderator

Re: Token for a specific day of the month

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?

ElisabethQ
Level 1

Re: Token for a specific day of the month

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

SanfordWhiteman
Level 10 - Community Moderator

Re: Token for a specific day of the month

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.

ElisabethQ
Level 1

Re: Token for a specific day of the month

Thank you.