Velocity script - extracting date from today's date | Community
Skip to main content
Level 9
November 22, 2017
Solved

Velocity script - extracting date from today's date

  • November 22, 2017
  • 1 reply
  • 5521 views

We have a weekly newsletter than I'm automating as much as possible. One piece I'm trying to put in dynamically is what we call Lifetime Deposits. If a customer cancels a tour, they can use their deposit for another tour whenever they like. It never expires.

So what I'm trying to do is to insert a block into our newsletter for customers who have Lifetime Deposits reminding them that they have money on file. The catch is that I don't want to do this every week - it will bloat our newsletter and become repetitive.

In coding terms, I thought this could be solved by doing something like this. Our newsletter deploys on a Saturday each week, so why not check the day of the month, and if it's between 1-7, drop in the block for qualifying customers? Then it would only show once a month, and I would never need to update the block.

So I was thinking...set a calendar object using today's date, then extract the date portion of that, and see whether that integer is in the range 1-7.

The functionality here: Adding Days and Comparing Dates is a start....using the toCalendar function, but from there, I'm not sure how to extract the day of the month only. I could do something based on the string but that seems dangerous given you might extract "07" and then compare that to an integer.

Any thoughts?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

Like so:

#set( $calNow = $date.getCalendar() )

#if( $calNow.get($field.in($calNow).DAY_OF_MONTH) <= 7 )

// Do stuff!

#end

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
November 22, 2017

Like so:

#set( $calNow = $date.getCalendar() )

#if( $calNow.get($field.in($calNow).DAY_OF_MONTH) <= 7 )

// Do stuff!

#end

Level 9
November 23, 2017

Works like a charm Thank you.

SanfordWhiteman
Level 10
November 23, 2017

For more related examples, check http://blog.teknkl.com/velocity-days-and-weeks/