cancel
Showing results for 
Search instead for 
Did you mean: 

JS new Date() shows Invalid Date

richard_pietsch
Active Contributor
0 Kudos

Hi all,
I am processing some dates within a script; however the "new Date()" command does not work anymore... it outputs "Invalid Date" when it's called with a date in ISO format, e.g.

var hiredate = Par.get("HIREDATE"); <<< it's 01.06.2019
var hiredateISO = new Date(custom_convertDate(hiredate)); <<< custom_convertDate returns 2019-06-01

hiredateISO is "Invalid Date".. why??

I cross tested the script snippets at w3schools and it was running as expected.. any hint?
Regards, Richard

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member85790
Participant
0 Kudos

Hi Richard,

Testing code snippets in a modern JS interpreter, while useful to an extent, can also lead you astray in some cases.

I've not determined exactly which JS engine is used by IDM, but if I am not mistaken it appears to be a very old version of Mozilla's code. This is inferred from the lack of certain functions and methods which more modern engines have implemented. The oldest example I've come across is the indexOf() array method, which has been implemented in browsers since around 2005, but is still not available in IDM. Unless it was purposefully removed, this would suggest the engine is at least this old.

Therefore, I would guess that support for ISO 8601 date strings as inputs to new Date() was a more recent addition to Javascript - I can't find specific details from a quick search, but hopefully this gives you a starting point to look into, if you are so inclined.

Kind regards,
Adam

richard_pietsch
Active Contributor
0 Kudos

Thanks for your input.. I did some further tests and noticed that the "YYYY/MM/DD" format does the trick..
Regards, Richard