Reputation: 117
I have a column (the first column in the sheet) of timestamp values. I am trying to perform a task if the timestamp date is from the day before do some task.
here is the code I came up with from reading other posts on StackOverflow and different sites on the web:
if(timestamp[0][0].setDate(timestamp[0][0].getDate()) === yesterday.setDate(yesterday.getDate())-1) {
do some task
}
However, it isn't working and I am not really sure where to go from here. The first column in my Google Sheet is where the timestamps are.
Upvotes: 1
Views: 1247
Reputation: 1595
here is the date from yesterday, should be able to use it with an If statement.
function myFunction() {
var MILLIS_PER_DAY = 1000 * 60 * 60 * 24;
var now = new Date();
var yesterday = new Date(now.getTime() - MILLIS_PER_DAY);
Logger.log(yesterday);
var formattedDate = Utilities.formatDate(new Date(now.getTime() - MILLIS_PER_DAY), "GMT", "MM/dd/yyyy HH:mm:ss");
Logger.log(formattedDate);
}
Upvotes: 2