Skip to main content
Level 4
Nov 11, 2021 11:04 AM UTC
Solved

Date Time functions, add days?

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.
Zahid_14
Zahid_14Accepted solution
Level 2
Aug 25, 2023 1:21 PM UTC

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

17 replies

Kishore_Reddy
Community Advisor
Community Advisor
Feb 6, 2022 4:05 PM UTC

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

Translate
kchaitanya
Level 3
Feb 9, 2022 11:48 PM UTC
mdonkeAuthor
Level 4
Feb 10, 2022 6:53 AM UTC

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

Translate
IvanMi1
Adobe Employee
Adobe Employee
Jun 1, 2022 9:54 PM UTC

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? 

Translate
mdonkeAuthor
Level 4
Jun 2, 2022 2:23 PM UTC

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.

 

 

Translate
Dec 7, 2022 10:57 AM UTC

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? 

Translate
Zahid_14
Level 2
Aug 21, 2023 5:31 AM UTC

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

Translate
Community Advisor
Aug 21, 2023 12:41 PM UTC
Zahid_14
Zahid_14Accepted solution
Level 2
Aug 25, 2023 1:21 PM UTC

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

Translate
Level 2
Nov 6, 2023 6:41 AM UTC

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") %}

Translate
_abhishek_
Level 3
Jul 17, 2024 10:48 AM UTC

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

 

Regards,

Abhishek

Translate
Adobe Employee
Jul 29, 2024 6:18 PM UTC

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") %}

 

Translate