Dynamically Insert Date in HTML5 Canvas Ad
Copy link to clipboard
Copied
I would like to create a display ad where the date displayed in the ad changes each day to: todays date +14 weeks.
I would also to be able to contol what element of the date I insert where, eg I will insert month in one place and date in another - see screenshot
Any ideas on the best way to achieve this?
Thanks!
Copy link to clipboard
Copied
use a dynamic textfield and the javascript Date() reference for the users date/time (which is so-so for accuracy), https://www.w3schools.com/jsref/jsref_obj_date.asp
eg,
this.tf.text = new Date();
Copy link to clipboard
Copied
I also needed the date to be in the future (and the month to be in name format) - figured it out as follows: Just added as custom javascript:
var month = new Array();
month[0] = "January";
month[1] = "February";
month[2] = "March";
month[3] = "April";
month[4] = "May";
month[5] = "June";
month[6] = "July";
month[7] = "August";
month[8] = "September";
month[9] = "October";
month[10] = "November";
month[11] = "December";
var d = new Date();
var numberOfDaysToAdd = 98;
d.setDate(d.getDate() + numberOfDaysToAdd);
var n = month[d.getMonth()];
document.getElementById("month").innerHTML = n;
document.getElementById("day").innerHTML = d.getDate();
<p id="month"></p>
<p id="day"></p>

