At the moment, i am using:
var d = new Date("March 7 2012");
document.write(d.getMonth() + 1);
What if the date string is something weird like No Date i.e:
var d = new Date("No Date"); // anything which isn't recognisable as a date
document.write(d.getMonth() + 1);
Here the output I get is NaN
How do I display a better message if something like this happens
You can check that the value is not
NaNby usingisNaN: