Date Time functions, add days? | Community
Skip to main content
Level 4
November 11, 2021
Solved

Date Time functions, add days?

  • November 11, 2021
  • 6 replies
  • 6570 views

Any tipps how I can add a given amount of days to a given datetime profile attribute?

 

E.g.

profile.mydate + 100 days

Thursday, 11 November 2021 + 100 days = Saturday, 19 February 2022

 

I checked https://experienceleague.adobe.com/docs/journey-optimizer/using/personalization/functions/dates.html?lang=en#set-days but couldn't find a way to achieve this.

 

Thank you!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Zahid_14

I have found a solution for calculated dates:
{% let d2 = currentTimeInMillis() + 14*86400000 %}
{% let ourDate = toDateTimeOnly(d2) %}
{%= formatDate(ourDate, "dd/MM/yyyy") %}

6 replies

Kishore_Reddy
Community Advisor
Community Advisor
February 6, 2022

Haven't experienced this yet. Please reach out to clientcare@adobe.com 

kchaitanya
Level 3
February 9, 2022
mdonkeAuthor
Level 4
February 10, 2022

Thank you @kchaitanya 

 

I'm aware this works in target. But the question is about a Journey Optimizer

https://experienceleague.adobe.com/docs/journey-optimizer/using/personalization/build-expressions/functions/dates.html?lang=en

Adobe Employee
June 1, 2022

hey @mdonke  can you help me to understand the usecase? Is this for a condition check, or you are trying to append data? Or just format/change a string? 

mdonkeAuthor
Level 4
June 2, 2022

Hi Ivan

 

I wanted to render some personalized text into AJO message content.

Example:

"Your contract will end Sept 1st 2022".

"Sept 1st 2022" should be calculated based on a profile attribute (like "contract/abc/contractStartDate") plus 2 years.

 

 

December 7, 2022

Hi, I'm currently trying to do the exact same thing (add 7 days to a dateTime field to get a new dateTime that is 7 days in the future). Is there already a solution or workaround for this? 

Zahid_14
Level 2
August 21, 2023

I am also trying to do the same thing. But it does not work. Please help me if anyone knows the solution. 
I tried to use it:
{% let d = today %}
{%= formatDate(setDays(d,7), "D/MM/YYYY") %}
but shows like this if today is 21st August, it will show 217-08-2023

Anuhya-Y
Community Advisor
Community Advisor
August 21, 2023
Zahid_14
Zahid_14Accepted solution
Level 2
August 25, 2023

I have found a solution for calculated dates:
{% let d2 = currentTimeInMillis() + 14*86400000 %}
{% let ourDate = toDateTimeOnly(d2) %}
{%= formatDate(ourDate, "dd/MM/yyyy") %}

Level 2
November 6, 2023

How to convert the specific date attribute value into milliseconds. So that we will use that attribute instead of currentTimeInMillis() like

{% let d2 = profile.dateAttribute + 14*86400000 %}
{% let ourDate = toDateTimeOnly(d2) %}
{%= formatDate(ourDate, "dd/MM/yyyy") %}

_abhishek_
Level 3
July 17, 2024

Did you get any solution for this to calculate "profile.mydate + 100 days"?

 

Regards,

Abhishek

Adobe Employee
July 29, 2024

I was able to add thirty days to the date+time field from the AEP dataset by first converting the attribute's year, month, and day to the milliseconds and then subtracting the milliseconds elapsed from the epoch time from each. Then add them all up and then also add the 30 days converted to milliseconds at the very end, the last "2592000000" value.

{% let someDate = "insert the profile date attribute here" %} someDate_from_ds: {%= someDate %} <br/> {% let someDate_inMillis = (someDate.getYear() * 31556952000 - 62167195440000) + (someDate.getDayOfMonth() * 86400000 - 86400000) + (someDate.getMonth() * 2629746000 - 2629746000) + (2592000000) %} someDate_inMillis: {%= someDate_inMillis %}<br/> {% let someDate_inMillis_formatted = toDateTimeOnly(someDate_inMillis) %} someDate_formatted_final_plus30_days: {%= formatDate(someDate_inMillis_formatted, "MM/dd/YYYY") %}