1

I have searched many of the date questions on here, but I am still stumped:

for (nn=3;nn<datacommit.length;++nn){ 
  var duedate1 = datacommit[nn][4]
  var duedate = Utilities.formatDate(duedate1,'GMT+0200','yyyy:MM:dd'); 

  var sevendaysfromnow1 = datacommit[nn][9]
  var sevendaysfromnow = Utilities.formatDate(sevendaysfromnow1,'GMT+0200','yyyy:MM:dd');

  if (+duedate==+sevendaysfromnow) { do my thing}};

Does not find a match when the same date is in those two separate columns. What am I doing wrong?

Alan Wells
  • 30,746
  • 15
  • 104
  • 152
user3456352
  • 95
  • 2
  • 12
  • Why is there a plus sign in front of `duedate` in the `if` condition? `if (+duedate==+sevendaysfromnow)` – Alan Wells Feb 06 '15 at 17:07
  • Do you know about `Logger.log()` statements? That prints information to the LOG. You can view what the code is returning by choosing the VIEW menu and the LOGS menu item. Use: `Logger.log(duedate + " : " + sevendaysfromnow);` to see how the two variables compare. – Alan Wells Feb 06 '15 at 17:14
  • I added the plus sign as suggested here:http://stackoverflow.com/questions/7606798/javascript-date-object-comparison – user3456352 Feb 06 '15 at 17:18
  • The logging is cool! I didnt know that. This is what I got from the log: [15-02-06 12:22:47:254 EST] 2015:01:01 : 2015:02:13 Any thoughts on how I format to get rid of [15-02-06 12:22:47:254 EST]? – user3456352 Feb 06 '15 at 17:23
  • Okay. That plus sign is meant to coerce a date object to a number. But I think that your variables are converted to a string with the `Utilities.formateDate()` function. And you should use triple equal signs, not double. – Alan Wells Feb 06 '15 at 17:24
  • Those are two different dates, aren't they? Or am I reading it wrong?. I'd get rid of the plus signs, and use triple equal signs. – Alan Wells Feb 06 '15 at 17:25
  • If you find out that the dates aren't equal, when you expected them to be, then the problem may be higher up in your code. You should also read the short section on using the debugger. [Google Documentation - Debugger and Breakpoints](https://developers.google.com/apps-script/troubleshooting#using_the_debugger_and_breakpoints) – Alan Wells Feb 06 '15 at 17:35

0 Answers0