• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Dynamically Insert Date in HTML5 Canvas Ad

New Here ,
Sep 24, 2020 Sep 24, 2020

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!

TOPICS
Ad development , Code , How to , Other , Performance

Views

460

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 25, 2020 Sep 25, 2020

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();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 05, 2020 Oct 05, 2020

Copy link to clipboard

Copied

LATEST

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines