Hi Team,
does anyone know how to convert date format (from YYYY-DD-MM to MM/DD/YYYY) in AC custom Personalization blocks in AEM Template?
We pull the AC email delivery content from AEM and use it in campaign. Issue is when i include the AC Personalization block in AEM Template. I want that PB dynamically populate the value in this format MM/DD/YYYY to recipient email. AC side it stores in YYYY-DD-MM postgres default date format.
I don't want to convert the date in AC using date format method. I want to convert it from AEM template.
Reason is if i make the conversation at PB level at AC side, it will fix the date format issue. but i can't use that PB for different countries date format.
is there any way it handles it AEM side through some method which can force it to delivered in MM/DD/YYYY ?
PB : <%= targetData.purchase_date %>
any idea community expert: @akshaaga @Marcel_Szimonisz @ParthaSarathy @david--garcia @_Manoj_Kumar_
Thanks!!!
Solved! Go to Solution.
Views
Replies
Total Likes
@Prady12, You can define a custom method in PB and invoke it to get the correct format data:
<%
function getDateInLocalFormat(dt){
var cc = recipient.countryCode;
if(cc == 'IN'){
// return IN format date
}else if(cc == 'US'){
// return US format date
}else{
// return generic format date
}
%>
<%=getDateInLocalFormat(targetData.purchase_date)%>
@Prady12, You can define a custom method in PB and invoke it to get the correct format data:
<%
function getDateInLocalFormat(dt){
var cc = recipient.countryCode;
if(cc == 'IN'){
// return IN format date
}else if(cc == 'US'){
// return US format date
}else{
// return generic format date
}
%>
<%=getDateInLocalFormat(targetData.purchase_date)%>
Thanks @ShashankNigam02 , I will try this approach and let you know results.
Views
Replies
Total Likes
You can convert the date format from YYYY-DD-MM to MM/DD/YYYY in your AEM Template using the SimpleDateFormat class in Java.
As an example-
<%
String purchaseDateStr = targetData.purchase_date;
SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-dd-MM");
SimpleDateFormat outputFormat = new SimpleDateFormat("MM/dd/yyyy");
Date purchaseDate = inputFormat.parse(purchaseDateStr);
String formattedDate = outputFormat.format(purchaseDate);
%>
<%= formattedDate %>
In this code, we first get the purchase_date value from the targetData object. We then create two SimpleDateFormat objects - inputFormat for parsing the input date string, and outputFormat for formatting the output date string. We then parse the input date string into a Date object using the inputFormat object.
Finally, we format the Date object into a string using the outputFormat object, and store the formatted string in the formattedDate variable.
You can then use the formattedDate variable wherever you need to display the formatted date in your AEM Template.
Note that the code assumes that the purchase_date value is always in the format "YYYY-DD-MM". If there is a possibility that the input format might vary, you may need to add some error handling to ensure that the parsing and formatting is done correctly.
Hi @Prady12,
Were you able to resolve this query with the help of the given solutions or do you still need more help here? Do let us know. In case the given solutions were helpful, then kindly choose the one that helped you the most as the 'Correct Reply'.
Thanks!
Views
Replies
Total Likes
Fixed that issue at upstream data provider system. same being used in PB to populate in email. Technically both solutions are correct.
Thanks for sharing with the Community!
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies