0

If I create a new Date with this String "08.12.2017 00:00:00" Google Apps Scripts return an Invalid date but when i try the example with jsfiddle it works.

Google Apps script

var limit = new Date("08.12.2017 00:00:00")

Invalid Date

Jsfiddle

var limit = new Date("08.12.2017 00:00:00");
console.log(limit);

Sat Aug 12 2017 00:00:00 GMT+0200 (Central Europe Daylight Time)

Why is that so?

Taaut
  • 437
  • 4
  • 15
  • "08.12.2017 00:00:00" is not consistent with ISO 8601, so ECMAScript parsers may interpret it any way they wish (including as invalid). See [*Why does Date.parse give incorrect results?*](https://stackoverflow.com/questions/2587345/why-does-date-parse-give-incorrect-results) – RobG Oct 27 '17 at 21:32

1 Answers1

3

Different engines, different parsing rules. Google Apps Script is based on Rhino. From the look at Rhino tests for date parsing you can guess it doesn't support a lot of datetime formats. The following are acceptable for it:

var limit = new Date("2017-12-08T00:00:00");  // in the timezone of the script
var limit = new Date("2017-12-08T00:00:00Z");  // in UTC

The date has to be yyyy-mm-dd, and it must be T and not a space in between date and time.