Format Date yyyy-mm-dd - Javascript

Format Date yyyy-mm-dd - Javascript

code snippet

javascript
Date.prototype.yyyymmdd = function () {
    var mm = this.getMonth() + 1; // getMonth() is zero-based
    var dd = this.getDate();

    return [this.getFullYear(),
            (mm > 9 ? '' : '0') + mm,
            (dd > 9 ? '' : '0') + dd
    ].join('-');
};

// to use it
new Date().yyyymmdd();

"Wonder rather than doubt is the root of all knowledge"

Contact me!

Have questions? Feel free to use the form or send me an email with any questions.

I will be responsive to your requests and your questions.