Reputation: 1
I'm new in programming and need your help.
Now I'm trying my own project ("Smart task google sheet"). The main thing about this project, it will sort your tasks by date, and when one day is left it will show you a message box ("Days left:1 on name of the task"). But I'm stuck now with date sorting. I can't sort it by "DD/MM/YYYY''. It's giving me some weird output. May you please provide me with a piece of code that may be done in Google Sheets -> Extensions -> App script?
Upvotes: 0
Views: 556
Reputation: 64140
Sort by date in column 1
function sortByDate() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName("Sheet0");
const vs = sh.getRange(2,1,sh.getLastRow() - 1, sh.getLastColumn()).getValues();
vs.sort((a,b) => {return new Date(a[0]).valueOf() - new Date(b[0]).valueOf()})
sh.getRange(2,1,vs.length,vs[0].length).setValues(vs);
}
Upvotes: 0