JavaScript RangeError – Invalid date

This JavaScript exception invalid date occurs if the string that has been provided to Date or Date.parse() is not valid.

Message:

RangeError: invalid date (Edge)
RangeError: invalid date (Firefox)
RangeError: invalid time value (Chrome)
RangeError: Provided date is not in valid range (Chrome)

Error Type:

RangeError

Cause of the Error: An invalid date string is provided to Date or Date.parse() method in the code.

Example 1: In this example, the invalid string is provided, so the error has occurred.



HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
new Date('2014-55-26').toISOString();
</script>

chevron_right


Output(In console):

RangeError: invalid time value

Example 2: In this example, the invalid string is provided, so the error has occurred.

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
var date = new Date('2020-57-16'); // Error here
date.toISOString();
</script>

chevron_right


Output(In console):

RangeError: invalid time value

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.