new Date("2018-06-19") throws invalid date error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2018 10:16 AM
Silly question, but does anyone know why following is not working on Jakarta Patch6, or is it just me 😞
var date3 = new Date("2018-06-19");
gs.print(date3.toString());
Throws Invalid Date error
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2018 10:25 AM
Try replacing - with / in dates.
Thanks,
Jaspal Singh
Hit Helpful or Correct on the impact of response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2018 10:29 AM
I am reading the date from a variable as this. Ideally it should be supported, just not sure why it's not.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.15

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2018 11:31 AM
if you just run below script you can see you get the output like : *** Script: Fri Apr 20 2018 11:27:33 GMT-0700 (PDT)
var date3 = new Date();
gs.print(date3);
so to get the value of the date for example date, month and year, you may need to call below functions to get the values.
getUTCDate() Same as getDate(), but returns the UTC date
getUTCDay() Same as getDay(), but returns the UTC day
getUTCFullYear() Same as getFullYear(), but returns the UTC year
getUTCHours() Same as getHours(), but returns the UTC hour
getUTCMilliseconds() Same as getMilliseconds(), but returns the UTC milliseconds
getUTCMinutes() Same as getMinutes(), but returns the UTC minutes
getUTCMonth() Same as getMonth(), but returns the UTC month
getUTCSeconds() Same as getSeconds(), but returns the UTC seconds
you can also refer: https://www.w3schools.com/js/js_dates.asp for more details.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2018 10:34 AM
Try something like below;
var gDate = new GlideDate();
gDate.setValue('2018-06-19');
gs.print(gDate);