I am currently using this JavaScript function (1 + CurrDate.getMonth()) to get the current month. It works fine, but i would like to know if it is possible to change the format of the output.
The current output for April = 4
and I would like to have the format of April = 04
ie ( YYYY-MM-DD)
i am fairly new to javascript, so would you please be very kind to direct me in the right direction if it is at all possible.
many thanks.
1. Use the "util.printd()" method to specidfy the entire formatted string.
util.printd("yyyy-MM-dd", CurrDate)
2. Use the "util.printf()" method to add the leading zero to the month.
util.printf("%,102d", (CurrDate.getMonth() + 1))
3. Add a leading character zero to the result of the calcualtion and substring the last 2 characters of the string.
var CurrMonth = "0" + (CurrDate.getMonth() + 1);
CurrMonth.substr(CurrMonth.length - 2, 2)
George Kaiser