Pedro
Pedro

Reputation: 3

Typescript array element Date not working

I am trying to compare various Date elements like this one 2 date elements that represent date formats but not being able to compare both cause it is displayed that "core.js:6237 ERROR TypeError: newticketList.createdAt.toDateString is not a function". And this as well with any other function like getDate or getMonth ps.: I already searched that it can be not recognized as a Date format, but in this case how can I go around it?

 ticketList: Array<Ticket>;
let dateTime = new Date()

(...)

this.ticketList = this.ticketList.filter(
      newticketList => (newticketList.createdAt.toDateString() != dateTime.toDateString()))

Upvotes: 0

Views: 530

Answers (2)

Pedro
Pedro

Reputation: 3

I got it done. although both vars are set as Date inside they were being handled as String So the solution was instead of:

newticketList => 
        (newticketList.createdAt.toDateString() != dateTime.toDateString()))

We get this:

newticketList => 
        (new Date(newticketList.createdAt).toDateString() != dateTime.toDateString()))

Upvotes: 0

Bj&#246;rn Hjorth
Bj&#246;rn Hjorth

Reputation: 2908

createdAt does no contain a method called toDateString

this.ticketList.map(
  newticketList => console.log(newticketList.createdAt));

And check what you get out

Upvotes: 0

Related Questions