Search code examples
angulartypescriptdateangular-date-format

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()))

Solution

  • 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()))