Now Date in V1 Email Template

Looking to be able to show the NowDate when sending a specific V1 email template

The template we are using is Subscription Notification, but no matter what is being tried, nothing is coming through.

The latest code we are trying is

#set($c=$spTools.class.forName("java.util.Calendar").getMethod("getInstance", null).invoke(null, null))
#set($nowDate=$c.getTime())
Now Date: $spTools.formatDate($nowDate, "M/d/y")

Any suggestions?
Thanks!

Try this
$__dateTool.format("MM-dd-yyyy", $__dateTool, $__dateTool.getLocale(), $__dateTool.getTimeZone().getTimeZone("EST"))

@masd1 -

This is tested and working in my environment.
Use the below -

#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

Output
Current Date:Wed Jan 24 01:35:56 PST 2024
Formatted Date:01/24/2024 01:35

The method I have used here is -

  * @param date Date to format
  * @param formatString Format String (i.e. MM/dd/yyyy HH:mm)
  * @return Formatted date string or empty string if date is null.
  * If the formatString is invalid, the formatted date will default
  * the short style date and time expected by the current locale
  */
public String formatDate(Object date, String formatString);

Mark it as solved, if it helps.

Thank you!

1 Like

Although i found my first code to be working today, I also found that @officialamitguptaa code also worked.

So two good solutions for the V1 Email Templates to add the Now Date to the outgoing email…
Now to get it in the Subject!!!

Thanks All

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.