SOLVED

Re: Velocity script - extracting date from today's date

Go to solution
Phillip_Wild
Level 10

Velocity script - extracting date from today's date

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?

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script - extracting date from today's date

Like so:

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

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

// Do stuff!

#end

View solution in original post

4 REPLIES 4
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script - extracting date from today's date

Like so:

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

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

// Do stuff!

#end

Phillip_Wild
Level 10

Re: Velocity script - extracting date from today's date

Works like a charm Thank you.

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script - extracting date from today's date

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

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script - extracting date from today's date

(And also note I broke my own rule above ... you actually need the time zone there as well for it to be reliable outside of CST. See the blog post for details.)