I am brand new to coding and trying to automate a process for a small organization. There is a form that employees fill out each day. I am attempting to write a script that I can run each morning that will remove any responses from dates that are NOT TODAY and archive them in a separate tab.
The key problem is that I can't seem to figure out how to write my code so that:
new Date(); === [the DATE value from the form response sheet]
returns TRUE when they are both the same day.
These are the variables I'm using:
var today = new Date();
var todayNoTime = today.setHours(0,0,0,0); // this was an attempt at a fix that isn't working so far
var dateRange = incomingSheet.getRange(1,1,incomingSheet.getLastRow(),1).getValues(); // these are all the timestamps from the form submissions
Then for the purposes of testing whether I've figured it out i'm using the following for loop:
for (i=0;i<incomingSheet.getLastRow();i++){
Logger.log((dateRange[i],1));
if (dateRange[i][1]===todayNoTime){Logger.log("row " + i + "matches todays date")}else{Logger.log("row " + i + " does not match todays date")}
I tried using .setHours(0,0,0,0) on each date range
ex. dateRange[i][1].setHours(0,0,0,0); but that doesn't work.
I tried using Utilities.formatDate to match the "var today;" to "var dateRange;" but the time remains a problem.
I've added a column to my sheet that uses the INT() function to convert the timestamp date to one of google's 5 digit date values, but I don't know how to convert "var today;" to one of those 5 digit codes automatically so that it works every day.
Any assistance or ideas would be much appreciated.