0

So, I have a line of code:

endYear = new Date(job['end_date']).getFullYear();  

where job['end_date'] evaluates to 'Dec 2015'.

In Chrome, Opera and Edge, this evaluates to 2015. In FireFox (both regular and develop edition), it evaluates to NaN.

What am I doing wrongly?

Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551
  • 1
    "Note: Parsing of date strings with the Date constructor (and Date.parse, they are equivalent) is strongly discouraged due to browser differences and inconsistencies." [Found here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date) – Barthy Sep 08 '20 at 08:21
  • 1
    That is not a valid date string in JavaScript. Use this instead `endYear=job['end_date'].split(' ')[1]` – str Sep 08 '20 at 08:24
  • Thanks, both, fell free to post an answer. @Found, I was going to go with `split()`, but just wanted to hear an explanation from the pros ;-) – Mawg says reinstate Monica Sep 08 '20 at 08:31

0 Answers0