The ability to create ideas and blogs are temporarily disabled. We apologize for the inconvenience.
Your developer community meets on the 4th Wednesday of each month. You want to send monthly invites from Marketo without having to hard-code anything. Earlier, we learned how to find the first 𝒀-day of next month, and this is just different enough to get its own post.
As always, start with the standard datetime includes in Velocity:
#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 add your campaign-specific settings, i.e. 4th Wednesday is $nth = 4, $day = "WEDNESDAY":
#set( $nth = 4 )
#set( $day = "WEDNESDAY" )
($day must be in all-caps English, since that’s how Java’s Calendar constants are stored.)
Next the hard/weird stuff:
#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) ) )
Now output $thisMonth any way you want:
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)}The 4th/nd Wednesday
of May 2024
is 05/22/2024
At the risk of making your head spin:
Easy, right? 😛
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.