masd1
(Michael Siskind)
February 12, 2024, 6:43pm
1
Is it possible to do date math in the V1 Email Templates?
Looking to get seven (7) days prior to the current date…
#set($dateObject=$spTools.getClass().forName("java.util.Date").newInstance())
#set($formattedDate=$spTools.formatDate($dateObject,"MM/dd/yyyy HH:mm"))
Current Date:$dateObject
Formatted Date:$formattedDate
Using the above from @officialamitguptaa , how can i get the Current Date to be seven days prior?
everything i have seen and read, has noty worked, and the Velocity site is limited in Date Math (maybe for a reason???)
baoussounda
(Ousmane N'DIAYE)
February 12, 2024, 9:38pm
2
Could you try this ?
#set($spToolsClass = $spTools.getClass())
#set($dateClass = $spToolsClass.forName("java.util.Date"))
#set($calendarClass = $spToolsClass.forName("java.util.Calendar"))
#set($dateObject = $dateClass.newInstance())
#set($calendarInstance = $calendarClass.getInstance())
$calendarInstance.setTime($dateObject)
$calendarInstance.add($calendarClass.DAY_OF_MONTH, 7)
#set($formattedDate = $spTools.formatDate($calendarInstance.getTime(), "MM/dd/yyyy HH:mm"))
Current Date: $dateObject
Formatted Date: $formattedDate
Hi @masd1 -
Use the below snippet, Its working -
#set($spToolsClass = $spTools.getClass())
#set($dateClass = $spToolsClass.forName("java.util.Date"))
#set($calendarClass = $spToolsClass.forName("java.util.Calendar"))
#set($dateObject = $dateClass.newInstance())
#set($calendarInstance = $calendarClass.getInstance())
$calendarInstance.setTime($dateObject)
$calendarInstance.add(5,-7)
#set($formattedDate = $spTools.formatDate($calendarInstance.getTime(), "MM/dd/yyyy HH:mm"))
Current Date: $dateObject
Formatted Date: $formattedDate
@baoussounda - You were close.
Please note - Here 5 is constant static value representing DATE. For more information refer the below Java doc from Oracle Java . You can use -7 to subtract 7 days from the current Date.
$calendarInstance.add(5,-7)
Mark it as solved, If it helps.
2 Likes
masd1
(Michael Siskind)
February 13, 2024, 3:40pm
4
Perfect and am seeing it working as expected!!!
thanks again @officialamitguptaa
system
(system)
Closed
April 13, 2024, 3:40pm
5
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.