I am attempting to sort the sheets within my spreadsheet in chronological order. They are all dates in the same format (MM-dd-yyyy), but I am unsure of how to treat them as a date while sorting, or whether that is even the best approach.
I currently have copied code that sorts it alphabetically, which gets the MM-dd part ordered correctly generally, but the years are not in order.
function sortSheets () {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheetNameArray = [];
var sheets = ss.getSheets();
for (var i = 0; i < sheets.length; i++) {
sheetNameArray.push(sheets[i].getName());
}
sheetNameArray.sort();
for( var j = 0; j < sheets.length; j++ ) {
ss.setActiveSheet(ss.getSheetByName(sheetNameArray[j]));
ss.moveActiveSheet(j + 1);
}
ss.setActiveSheet(ss.getSheetByName("GUI"));
ss.moveActiveSheet(1);
}
This is currently what my code looks like, but again it is just meant to alphabetize rather than sort chronologically. The results that I hope to receive would be the tabs being in order, 1 being "GUI", and 2 onward sorted from earliest date to latest date.