0

I saw this code:

var DAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday',
            'Saturday', 'Sunday'];

  var pastQuery = 'SELECT ' + fields +
      ' FROM ACCOUNT_PERFORMANCE_REPORT WHERE DayOfWeek=' +
      DAYS[getDateStringInTimeZone('u', new Date())].toUpperCase() +
      ' DURING ' + dateRangeToStart + ',' + dateRangeToEnd;

How does getDateStringInTimeZone('u', new Date()) returns an index for DAYS array?

function getDateStringInTimeZone(format, date, timeZone) {
  date = date || new Date();
  timeZone = timeZone || AdsApp.currentAccount().getTimeZone();
  return Utilities.formatDate(date, timeZone, format);
}

I thought Utilities.formatDate(date, timeZone, format) returns a string.

Elad Benda
  • 35,076
  • 87
  • 265
  • 471
  • https://stackoverflow.com/questions/28956532/google-apps-script-date-format-issue-utilities-formatdate – Ctznkane525 Aug 12 '21 at 00:06
  • do you need to cast your string to a number? - u Day number of week (1 = Monday, ..., 7 = Sunday) Number 1 – Ctznkane525 Aug 12 '21 at 00:08
  • It's a code I'm reading. I assumed it should return an int index. Otherwise how would it be used with the `DAYS` array? – Elad Benda Aug 12 '21 at 00:30
  • the function itself returns a string, so i would presume you would need to parseInt before trying to use it as an array index – Ctznkane525 Aug 12 '21 at 00:40

0 Answers0