I am trying to check if one date is greater than another date using google script. I am extracting a date from the spreadsheet and formatting it. Then I check it against today's date. If today's date is less than the extracted date, some functionality has to be done.This is as far as I have got.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet1 = ss.getSheetByName("Sheet1"); //activating a particular sheet
var data = sheet1.getRange(2, 1, sheet1.getLastRow(), 100).getValues();
for (var row = 0; row < data.length; row++) {
var todayDate = Utilities.formatDate(new Date(), "GMT", "MM/dd/yyyy");
var dueDate = new Date(data[row][17]);
//Logger.log("Due: "+dueDate);
var nRow = row+1;
dueDate.setDate(dueDate.getDate()+1);
var curDate=Utilities.formatDate(dueDate, "GMT", "MM/dd/yyyy");
//Logger.log("Current: "+curDate);
if(curDate>todayDate){
Logger.log("Today: "+todayDate);
Logger.log("Current: "+curDate);
Logger.log("In");
}
}
I am able to log the values but the if()
statement does not seem to work. Where have I gone wrong?
Problem got solved. Solution was:
if(curDate.valueOf()>todayDate.valueOf()){}
It is now working.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With