I need the script copied below to hide rows prior to today's date for the spreadsheet linked below.
Spreadsheet: [login to view URL]
Script:
/**
* Looks for rows with old dates, and hides them if so.
* It finds the date column my checking the first column for the word 'Date'.
*/
function hideOldRows(colNum) {
var ss = [login to view URL]('1d0-hBf96ilIpAO67LR86leEq09jYP2866uWC48bJloc');
var sheet = [login to view URL]()[0];
var header = [login to view URL](4, 1, 1, [login to view URL]());
var colNum = [login to view URL]()[0].indexOf('Date') + 1;
if (colNum === 0) {
[login to view URL]([login to view URL]());
throw Error('Could not find the word Date on the first row');
}
var rows = [login to view URL](1, colNum, [login to view URL](), 1);
var numRows = [login to view URL]();
var values = [login to view URL]();
for (var i = 0; i <= numRows - 1; i++) {
var row = values[i];
if (isDate(row[0]) && isOld(row[0])) {
[login to view URL](i + 1);
}
}
};
function isDate(dateString) {
return (new Date(dateString)) != "Invalid Date"; // notice not !==
}
function isOld(dateString) {
assert(isDate(dateString));
var inDate = (new Date(dateString)).getTime();
var yesterday = new Date();
[login to view URL]([login to view URL]() - 1);
return yesterday > inDate;
}
function assert(b, msg) {
msg = msg || "default message";
if (!b) {
throw Error(msg)
}
}
function test() {
assert(isOld('Fri Jan 04 00:00:00 GMT-05:00 2013'));
assert(!isOld('Fri Jan 04 00:00:00 GMT-05:00 2018'));
}
/**
* Adds a custom menu to the active spreadsheet, containing a single menu item
* for invoking the readRows() function specified above.
* The onOpen() function, when defined, is automatically invoked whenever the
* spreadsheet is opened.
* For more information on using the Spreadsheet API, see
* [login to view URL]
*/
function onOpen() {
var sheet = [login to view URL]();
var entries = [{
name : "Hide Old Rows",
functionName : "hideOldRows"
}];
[login to view URL]("Scripts", entries);
};