Reputation: 329
I have a Google Spreadsheet that I building to manage my family's food storage. The main part I am using Google Apps Script for is to send me email alerts when something is within 60 days of expiring.
You can see the script by going to Tools > Script Editor (which you probably already assumed.)
I am having trouble with lines 74 and 80. When I run the script and check the log, I am getting 12/32/2015 and 11/31/2015. How can I get these to appear as 1/1/2016 and 12/1/2015?
Thanks
Upvotes: 1
Views: 108
Reputation: 4273
You can use Utilities.formatDate()
. Read more about Utilities class.
Replace line 74,
message1 += '1 ' + alertsArray[i][1] + ' of ' + alertsArray[i][0] + ' is going to expire on ' + (new Date(alertsArray[i][4]).getMonth() + 1) + '/' + (new Date(alertsArray[i][4]).getDate() + 1) + '/' + new Date(alertsArray[i][4]).getYear() + '. <br/>';
with this,
message1 += '1 ' + alertsArray[i][1] + ' of ' + alertsArray[i][0] + ' is going to expire on ' + Utilities.formatDate(new Date(alertsArray[i][4]), "GMT-07:00", "''MM/dd/yyyy")) + '. <br/>';
Do the same to line 80.
Upvotes: 1