C
C
cb77772020-10-12 13:23:52
JavaScript
cb7777, 2020-10-12 13:23:52

How to check if an array element is a date?

Good afternoon, a dynamic array is returned from the backend, containing different data (*example of one line):

-101   2019-03-01T00:00:00	2019-03-01T00:00:00	начисление	Х	---	---

I need to format the date in the dd.MM.yyyy format, in a regular static table I did it through the pipe date format, but this will not work here, i.e. you need to implement your own pipe, but I have not worked with this before.
It turns out that here you need to use a regular expression? Here I created my own pipe for example, but it does not work.
@Pipe({
  name: 'armDate'
})
export class ArmDatePipe implements PipeTransform {

  transform(date): any {
  	 const regexp = "(\\d{4}-\\d{2}-\\d{2})[A-Z]+(\\d{2}:\\d{2}:\\d{2})";
  	 
  	 	if(date !== undefined || date !== null){
  	 		date.replace(regexp);
  	 		return date;
    }
  	 return  date;
  }

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mario Kun, 2020-10-12
@marioKun

@Pipe({
  name: 'armDate'
})
export class ArmDatePipe implements PipeTransform {

  transform(date): any {
         let myvar = new Date(date);
        if(myvar instanceof Date && myvar.getMonth()){
             return  date;
        }
             return date;
    }
  	 
  }

}

Maybe something like this?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question