Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

does the filter with new date() accept format other than yyyy-mm-dd?

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading