I needed a script that will delete rows from a Google sheet if their timestamp goes past the inactivity date, which is 31 days past from today's date. I found a script that could do this and just modified it a little to fit my needs. It didn't work. I spent 30 minutes trying to figure out what isn't working and finally realized through logs, that when Apps Script pulls the date from the sheet, it pulls this:
Mon Aug 24 06:33:33 GMT+01:00 2020
instead of the number format of dates for Google Sheet. I need a way to convert that date to the number format. This is the script that I was working on:
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('RAW - Roll Call');
var values = sheet.getDataRange().getValues();
var today = Date.now()/86400000 + 25569;
var inactivityDate = today-31;
for (var i = values.length - 1; i >= 0; i--) {
if (values[i][0] < inactivityDate) {
sheet.deleteRow(i+1);
}
}
}