Date Looping

Description

This is how you can loop over a range of dates in velocity

Code

${esc.hash}set(${esc.dollar}start = ${esc.dollar}date.toDate("MM/dd/yyyy","02/25/2013"))
${esc.hash}set(${esc.dollar}end = ${esc.dollar}date.toDate("MM/dd/yyyy","03/10/2013"))

${esc.hash}${esc.hash} D = Day of Year
${esc.hash}set(${esc.dollar}startDOY = ${esc.dollar}date.format("D", ${esc.dollar}start))
${esc.hash}set(${esc.dollar}endDOY = ${esc.dollar}date.format("D", ${esc.dollar}end))
${esc.hash}set(${esc.dollar}days = ${esc.dollar}math.abs(${esc.dollar}math.sub(${esc.dollar}startDOY, ${esc.dollar}endDOY)))

<p> There are ${esc.dollar}days days between ${esc.dollar}date.format("MM/dd/yyyy", ${esc.dollar}start) and ${esc.dollar}date.format("MM/dd/yyyy", ${esc.dollar}end) </p>

<ul>
${esc.hash}foreach(${esc.dollar}d in [0..${esc.dollar}days])
  <li>The date: ${esc.dollar}date.format("MM/dd/yyyy", ${esc.dollar}UtilMethods.addDays(${esc.dollar}start, ${esc.dollar}d))</li>
${esc.hash}end
</ul>