I am working on report generation module and I am checking if the value in each record a date for formatting purpose.
var records = [{
recordNumber : "CNE-TEST-00056",
name : "Test Name 1",
createdAt: "2018-03-12"
}, {
recordNumber : "CNE-TEST-00057",
name : "Test Name 2",
createdAt: "2018-01-26T18:30:00.000Z"
}];
These are the records in my report. The keys in each object will be dynamic and I want to know what type they are of actually.
I am trying to know type Date
by using function below.
function isDate(date){
var date1 = new Date(date);
if(isNaN(date1.getFullYear()) || date1.getFullYear() == 1970){
return false;
}
return true;
}
When I do new Date("CNE-TEST-00056")
it should technically return me Invalid Date
and new Date("CNE-TEST-00056").getFullYear()
should return NaN
. But it returns Sun Jan 01 1956 00:00:00 GMT+0530
.
How can I make it say "CNE-TEST-00056"
is not a date.