1

I have a response from mydatepicker in the following format

{
 "isRange":false,
 "singleDate":{
  "date":{
     "year":2022,
     "month":5,
     "day":13
  },
  "jsDate":"2022-05-13T03:00:00.000Z",
  "formatted":"13-05-2022",
  "epoc":1652410800
 },
 "dateRange":null
}

I have a filter that uses the new date(), but it seems that it doesn't accept it accepting the date in the value dd-mm-yyyy and I would need to display it like this, not like this yyyy-mm-dd

  filterPeriodos() {
const d = new Date(this.formGeral.value.data.singleDate?.formatted + 'T23:59');
if (this.storeS.layout.emp.id === 1) {
    if(this.formGeral.value.entregaBool){
        return this.periodos.filter( transpId =>   transpId.ativo === (1) && transpId.transporte_id === (this.metodoId) && transpId.week[d.getDay()] === 1 ) ;
    }
   }
 return this.periodos;
}

would anyone have any suggestions?

Leonardo
  • 47
  • 6
  • Why not use .jsDate? – danh May 13 '22 at 13:22
  • @danh I tried in the following way, it seems that the filter didn't work const d = new Date(JSON.stringify(this.formGeral.value.data.singleDate.jsDate) + 'T23:59'); – Leonardo May 13 '22 at 13:38

1 Answers1

0

To get the end of a day, first convert the parse-able text into a date, then manipulate that date.

let object = this.formGeral.value.data;          // for our sanity
let jsDate = new Date(object.singleDate.jsDate);
jsDate.setUTCHours(23,59,59,999);

Keep the formatted string around for display, but do any date computations on the real date object.

danh
  • 62,181
  • 10
  • 95
  • 136