Hi. We have a membership-based organization.
We have field data for $lead.aornPaidThru date. This is the member's renewal date.
I am trying to subtract 89 days from the $lead.aornPaidThru date to display a date that's 90 days in advance of the member's renewal date.
I'm not that familiar with Velocity (probably obvious).
Here's what I've put together, but it is not working. I do not have a developer available to assist with this, so I'm hoping for a little help here from the community, please.
When I run this in a Marketo email with a member, all that displays for the token result is:
aornPaidThru is not in the future
#set( $DAYS_OFFSET_BASE = 89 )
#set( $ret = $calNow.set(
$calNow.get($calConst.YEAR),
$calNow.get($calConst.MONTH),
$calNow.get($calConst.DAY_OF_MONTH),
0,
0,
0
) )
#set( $ret = $calNow.set($calConst.MILLISECOND,0) )
#set( $calRenewDate = $convert.toCalendar(
$convert.parseDate(
$lead.aornPaidThru,
$ISO8601DateOnly,
$defaultLocale,
$defaultTimeZone
)
) )
#set( $daysUntilRenewDate = $date.difference($calNow,$calRenewDate).getDays() )
#if( $daysUntilRenewDate > 0 )
#set( $daysOffsetFromBase = $math.sub($DAYS_OFFSET_BASE, $daysUntilRenewDate) )
aornPaidThru offset is $daysOffsetFromBase.
#else
aornPaidThru is not in the future.
#end
Solved! Go to Solution.
My intended logic is if a member's PaidThruDate is, for example 2022-04-30, then the calculation would substract 90 days and display that date, 2022-01-30.
Then you want
## standard date math includes
#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" )
##
#set( $DAYS_OFFSET_BASE = 90 )
#set( $ret = $calNow.set(
$calNow.get($calConst.YEAR),
$calNow.get($calConst.MONTH),
$calNow.get($calConst.DAY_OF_MONTH),
0,
0,
0
) )
#set( $ret = $calNow.set($calConst.MILLISECOND,0) )
#set( $calRenewDate = $convert.toCalendar(
$convert.parseDate(
$lead.aornPaidThru,
$ISO8601DateOnly,
$defaultLocale,
$defaultTimeZone
)
) )
#if( $date.difference($calNow,$calRenewDate).getDays() > 0 )
#set( $isRenewDateInFuture = true )
#else
#set( $isRenewDateInFuture = false )
#end
#if( $isRenewDateInFuture )
#set( $calOffset = $calRenewDate.clone() )
#set( $void = $calOffset.add($calConst.DATE,-90) )
Paid through ${date.format($ISO8601DateOnly,$calOffset,$defaultLocale,$defaultTimeZone)}.
#else
Renewal date is not in the future.
#end
This is as far as I got.
Well, you need to include the includes from Always include this bit, or references like $calNow don’t have any meaning!
## standard date math includes
#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" )
##
#set( $DAYS_OFFSET_BASE = 89 )
#set( $ret = $calNow.set(
$calNow.get($calConst.YEAR),
$calNow.get($calConst.MONTH),
$calNow.get($calConst.DAY_OF_MONTH),
0,
0,
0
) )
#set( $ret = $calNow.set($calConst.MILLISECOND,0) )
#set( $calRenewDate = $convert.toCalendar(
$convert.parseDate(
$lead.aornPaidThru,
$ISO8601DateOnly,
$defaultLocale,
$defaultTimeZone
)
) )
#set( $daysUntilRenewDate = $date.difference($calNow,$calRenewDate).getDays() )
#if( $daysUntilRenewDate > 0 )
#set( $daysOffsetFromBase = $math.sub($DAYS_OFFSET_BASE, $daysUntilRenewDate) )
aornPaidThru offset is $daysOffsetFromBase.
#else
aornPaidThru is not in the future.
#end
I’m not actually sure what your intended logic is, but if the $lead.aornPaidThru is “2021-07-08” (a week from now) then $daysOffsetFromBase is 82.
I appreciate your help and patience with me as I learn this.
My intended logic is if a member's PaidThruDate is, for example 2022-04-30, then the calculation would substract 90 days and display that date, 2022-01-30.
My intended logic is if a member's PaidThruDate is, for example 2022-04-30, then the calculation would substract 90 days and display that date, 2022-01-30.
Then you want
## standard date math includes
#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" )
##
#set( $DAYS_OFFSET_BASE = 90 )
#set( $ret = $calNow.set(
$calNow.get($calConst.YEAR),
$calNow.get($calConst.MONTH),
$calNow.get($calConst.DAY_OF_MONTH),
0,
0,
0
) )
#set( $ret = $calNow.set($calConst.MILLISECOND,0) )
#set( $calRenewDate = $convert.toCalendar(
$convert.parseDate(
$lead.aornPaidThru,
$ISO8601DateOnly,
$defaultLocale,
$defaultTimeZone
)
) )
#if( $date.difference($calNow,$calRenewDate).getDays() > 0 )
#set( $isRenewDateInFuture = true )
#else
#set( $isRenewDateInFuture = false )
#end
#if( $isRenewDateInFuture )
#set( $calOffset = $calRenewDate.clone() )
#set( $void = $calOffset.add($calConst.DATE,-90) )
Paid through ${date.format($ISO8601DateOnly,$calOffset,$defaultLocale,$defaultTimeZone)}.
#else
Renewal date is not in the future.
#end
Thank you! This is a huge help.