Expand my Community achievements bar.

Announcing the launch of new sub-community for Campaign Web UI to cater specifically to the needs of Campaign Web UI users!
SOLVED

HTML personalization - how to get first day of current month and x days after

Avatar

Level 5

Hello everyone,

 

I try to get in my HTML delivery something like this with the date and make a personalization, here is my example :

You can travel between the 01/04/2022 until the 15/05/2022 

 

So I want to get the first day of the current month until another day + 45 days for example.

Is something like this possible with personalization ? Can someone help me on this possible code ?

 

Thank you in advance for your help.

Kind regards.

EDIT : 

I successfully got the first day of current month with this :

var date = new Date();
var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);

Result

<%= formatDate(firstDay, "%2D/%2M/%4Y") %>

 

Question remain is, how to get the other date + 45 days based on the firstDay ?

Thank you for your help.

 

 

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hello @thibaultb473199 ,

for example taken from https://stackoverflow.com/questions/563406/how-to-add-days-to-date 

 

Date.prototype.addDays = function(days) {
    var date = new Date(this.valueOf());
    date.setDate(date.getDate() + days);
    return date;
}

var date = new Date();

console.log(date.addDays(5));

Marcel

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

Hello @thibaultb473199 ,

for example taken from https://stackoverflow.com/questions/563406/how-to-add-days-to-date 

 

Date.prototype.addDays = function(days) {
    var date = new Date(this.valueOf());
    date.setDate(date.getDate() + days);
    return date;
}

var date = new Date();

console.log(date.addDays(5));

Marcel