HTML input prepopulate date

html, javascript

Solution

Populate with today's date:

var today = new Date();
document.getElementById("toDate").value = today.getFullYear() + "-"
        + String(today.getMonth() + 101).slice(-2) + "-"
        + String(today.getDate() + 100).slice(-2);

6 month in the past:

var past = new Date();
past.setMonth(past.getMonth() - 6); //
document.getElementById("toOldDate").value = past.getFullYear() + "-"
        + String(past.getMonth() + 101).slice(-2) + "-"
        + String(past.getDate() + 100).slice(-2);

Problem

Am rediscovering HTML after quite some time. I am using just HTML and javascript along with Salesforce. I have two date input fields. I was curious to see if there is any easy way to populate these fields with: a. Today's date b. Date 6 months before today. ``` <input type="text" id="toDate" size="10" onmouseover="initialiseCalendar(this, 'toDate')"/> ``` Thanks, Calvin

Original source