Return Last 4 months using velocity

bryantchang
Level 2

Return Last 4 months using velocity

Trying to return current month + last 4 months in 3 letter abbreviation using velocity.

This is what I have, but I'm sure there's a better way? 😅

 

#set( $calNow = $date.getCalendar() )
#set( $calNowMinus1 = $date.getCalendar() )
#set( $calNowMinus2 = $date.getCalendar() )
#set( $calNowMinus3 = $date.getCalendar() )
#set( $calNowMinus4 = $date.getCalendar() )
$calNowMinus1.add(2,-1)
$calNowMinus2.add(2,-2)
$calNowMinus3.add(2,-3)
$calNowMinus4.add(2,-4)
#set( $CurrentMonth = $date.format('MMM',$calNow) )
#set( $CurrentMonthMinus1 = $date.format('MMM',$calNowMinus1) )
#set( $CurrentMonthMinus2 = $date.format('MMM',$calNowMinus2) )
#set( $CurrentMonthMinus3 = $date.format('MMM',$calNowMinus3) )
#set( $CurrentMonthMinus4 = $date.format('MMM',$calNowMinus4) )

Current Month: $CurrentMonth<br>
Current Month Minus 1: $CurrentMonthMinus1<br>
Current Month Minus 2: $CurrentMonthMinus2<br>
Current Month Minus 3: $CurrentMonthMinus3<br>
Current Month Minus 4: $CurrentMonthMinus4