Email Template Date

I’m facing an issue with displaying current date in new account provisioned email template.
I’ve used the datetool global variable and it’s working for test email. However when the email is generated, it is not showing the date.

Created Date: $__dateTool.get(‘yyyy-MM-dd’)

This is how it looks in the test email:


However, when the actual email is generated it looks like this:

Hope someone have a solution here. Thanks!

Hello @yuyanglee
Here are the options with you and their output with documentation to help you with dates in future.

$date.get('y-M-d H:m:s')

$date.get('y-M-d')

$date.getDate()

The results would be like:

2023-12-14 16:6:54

2023-12-14

Thu Dec 14 16:06:54 GMT 2023

HI Harsh,

Weirdly, i’m still getting the similar issue:
image

Hello @yuyanglee We have classifies this as a BUG, support team will get back to you with the case details for the one you have raised the support ticket.
Thanks

Hi @harshamin9,
Does the above recommendations only works for email template version 2?
Could this be the reason since I’m using New Account Provisioned email template?

Hello @yuyanglee
Yes, the above solution works only for V2 Templates and here are more ways to do so.
If you need to change the format of a date within an email template, use a two step process:

  1. Convert the incoming date string to a date object
  2. Format the date object to the desired string

For example, if you have a variable named $certStartDate which is a string that looks like this:

Sat, 13 Jan 2024 12:00:00 GMT

You need to first build the date object by parsing the field, using the .toDate method, like so:

#set($certStartDateObj = $__dateTool.toDate("EEE, dd MMM yyyy HH:mm:ss zzz",$certStartDate))

Then, you can use the .format method to set a new variable with the desired fields:

#set($certStartDateObjFrench = $__dateTool.format("dd/MM/yyyy", $certStartDateObj))

#set($certStartDateObjEnglish = $__dateTool.format("MM/dd/yyyy", $certStartDateObj))

And finally, you can reference those variables in the body of the email template.

1 Like

This is working and tested -
#set($dateObject=$spTools.getClass().forName(“java.util.Date”).newInstance())
Current Date:$dateObject

Mark it as solved, If it helps.

1 Like

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