Simple_tech
Simple_tech

Reputation: 49

How to return dates where task end_date is true in javascript

I want to return not one date but all the task that has ended.

Assumning my end_date Task are

so far the code below only return

My code is

const CalTaskHasEnded = Task => {
      return new Date(task.end_date).getDay() === new Date().getDay();
   };

But this only returns one date from the list of dates where task has ended.

How to write this code to be able to return all the tasks that has gotten its end_date. i.e task that has ended.

Upvotes: 0

Views: 212

Answers (2)

Simple_tech
Simple_tech

Reputation: 49

Thanks RamiReddy for your time, I have solved this like this

const calTaskHasEnded = Task => {
    if (task.has_ended){
       return new Date().getDay();
       }
    };

Upvotes: 0

sriam980980
sriam980980

Reputation: 2028

you can check date before or not

const CalTaskHasEnded = (task:Task ) => {
      return new Date(task.end_date).getTime() <= new Date().getTime();
   };
 
 let tasks = [{
    end_date:'Jan. 30 2020'
},{
    end_date:'Jan. 30 2017'
},
{
    end_date:'Jan. 30 1987'
},
{
    end_date:'Jan. 30 2027'
}]

console.log(tasks.filter(CalTaskHasEnded));

Upvotes: 2

Related Questions