Convert date to format YYYYMMDD

The below function can be used to convert a date value to format YYYYMMDD.

function (inputDate) {
// convert to YYYYMMDD
var date = new Date(inputDate);
var d = date.getDate();
var m = date.getMonth() + 1;
var y = date.getFullYear()
var dateString = (y+(m <= 9 ? '0' + m : m)+(d <= 9 ? '0' + d : d));
var outputDate = format.parse({
value: dateString,
type: format.Type.DATE
});
return outputDate;
}

Leave a comment

Your email address will not be published. Required fields are marked *