Home > database >  Utilities.formatDate() returning month as 0
Utilities.formatDate() returning month as 0

Time:09-08

row[0] is a date formatted such that is shows as 8/16/22 in google sheets.

And for the code,

var date = Utilities.formatDate(new Date(row[0]), SpreadsheetApp.getActiveSpreadsheet().getSpreadsheetTimeZone(), "m/d/yy");
SpreadsheetApp.getUi().alert(date);

I expected the output of 8/16/22 but instead get the following:

actual ouput

My end goal is to have this date be pasted into a google doc template using the following line:

body.replaceText('{{date}}', date);

And here is the output of just SpreadsheetApp.getUi().alert(new Date(row[0]));

output without formatting

CodePudding user response:

As written in official documentation:

m is minute, use M instead.

  • Related