Regex is far too complicated for me but I'm certain it can solve my issue.
I have file names that include a date written out.
Example "January 3, 2020".
I wish to change the format to YYYYMMDD ("20200103").
Any help is greatly appreciated.
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('');
};
function getSecondPart(str) {
return str.split(' ')[1];
}
function getFirstPart(str) {
return str.split(' ')[0];
}
var d = Date.parse(getSecondPart(name));
newName = getFirstPart(name) + ' ' + d.yyyymmdd();