Set Div to Today's Date
Dynamically add today's date to a div on your Webflow site. A perfect way to easily display the current date on your site without any headaches.
Dynamically add today's date to a div on your Webflow site. A perfect way to easily display the current date on your site without any headaches.
How to add it
- Add the Javascript code to your sites body closing custom code section
- Set the target div's element ID with output
The code
Javascript
<!-- Add to closing body section -->
<!-- Current date script -->
<script>
var today = new Date();
var day = today.getDate();
var month = today.getMonth() + 1;
var year = today.getFullYear();
if (day < 10) {
day = '0' + day
}
if (month < 10) {
month = '0' + month
}
var out = document.getElementById("output");
out.innerHTML = month + "/" + day + "/" + year;
</script>
<!-- Customize the date output -->
<script>
var today = new Date();
var day = today.getDate();
var day1 = today.getDate() + 1;
var day2 = today.getDate() + 2;
var month = today.getMonth() + 1;
var year = today.getFullYear();
var months = new Array(12);
months[0] = "January";
months[1] = "February";
months[2] = "March";
months[3] = "April";
months[4] = "May";
months[5] = "June";
months[6] = "July";
months[7] = "August";
months[8] = "September";
months[9] = "October";
months[10] = "November";
months[11] = "December";
var out = document.getElementById("milestone1");
out.innerHTML = month + "/" + day + "/" + year;
var out = document.getElementById("milestone2");
out.innerHTML = month + "/" + day + "/" + year;
var out = document.getElementById("milestone3");
out.innerHTML = month + "/" + day1 + "/" + year;
var out = document.getElementById("milestone4");
out.innerHTML = month + "/" + day1 + "/" + year;
var out = document.getElementById("milestone5");
out.innerHTML = month + "/" + day2 + "/" + year;
var out = document.getElementById("milestone6");
out.innerHTML = month + "/" + day2 + "/" + year;
var out = document.getElementById("milestone3m");
out.innerHTML = months[month] + " " + day1;
var out = document.getElementById("milestone6m");
out.innerHTML = months[month] + " " + day2;
</script>