I’ve got a problem passing off date information to another site because they still require two digit dates even for the first nine days of the month. I’ve gotten 90% of the way using the code from the SO page for set select list to current date using Jquery. That moves the months and days from 1-31 and 1-12. I need the output to be from 01-31 and 01-12.
The current situation:
function ragequit() {
var today = new Date();
var daym = today.getDate();
var monthm = today.getMonth();
$('#StartMonth option[value=' + (monthm) + ']').prop('selected',true);
$('#StartDay option[value=' + (daym) + ']').prop('selected',true);
$('#EndMonth option[value=' + (monthm+1) + ']').prop('selected',true);
$('#EndDay option[value=' + (daym+1) + ']').prop('selected',true);
}
It is calling the month perfectly because this is December. Also had to add m to each of the values so that it doesn’t compete with another tool that increments the date when the start date is changed.
Simply put, I have 12 7 2011 – I need 12 07 2011.
What you need is a function to pad a string with leading zeros, like this:
Then you can use this to add leading zeros to your dates: