I have input on a Google spreadsheet specific dates that an e-mail should be sent. I have a script that gets the values from the spreadsheet to either (1) compare whether the "date email should be sent" equals today, if so, run script or (2) input into the spreadsheet today's date, which is the "date email was sent".
I am seeing the logger report 1 day behind the date that is actually in the spreadsheet. Example: Spreadsheet shows 3/11/2015 , and logger shows Tue Mar 10 22:00:00 PDT 2015, GMT-6:00, MM-dd-yyyy
.
Is this a result of daylight savings time? I have read of people having similar problems related to DST and scripts/triggers/spreadsheets.
The time zones for the Script Project and the Spreadsheet itself are both set to GMT-6 (central time), so there is no discrepancy there. I wasn't having this problem (to my knowledge) before the time change. Session.getTimeZone()
although depreciated returns correct time zone (GMT-6).
If I use new Date()
it returns today's date correctly. When I use Utilities.formatDate(sheet.getRange("A1:A1").getValue(), "GMT-6", "MM-dd-yyyy");
(where cell A1 contains the date) it reports in the log as 1 day behind what the actual date is showing on the spreadsheet.
What I have tried:
Formatting time zone as "GMT-6:00" instead of just "GMT-6" makes no difference, although user Sergi suggested the change here.
I tried referencing "today's date" from the spreadsheet (using
=today()
) instead of through the script withnew Date ()
. This still causes the problem. When the script records "date email was sent (which is today)" back into the spreadsheet, it shows as 1 day behind.
Other options? Answer #6 on Google Script issues and Sergi's answer again suggested converting it to a string. Can someone explain (1) what the difference is in doing so and (2) how I would write it if referencing a cell value instead of new Date
. Is it like this after defining the FUS1 variable?
Utilities.formatDate(sheet.getRange("A1:A1").getValue(), FUS1 , "MMM-dd-yyyy h:mm a");
Thank you!!