How can I check if an element of an array is a date?

  • 0
    Good afternoon, a dynamic array containing different data is returned from the backend (* 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 the format via pipe date, but this will not work here, i.e. you need to implement your pipe, but I have not worked with a similar one before.
    It turns out that here you need to use a regular expression? I created my own pipe for example, but it doesn't 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;
      }
    
    }
    JavaScript Anonymous, Oct 15, 2019

  • 1 Answers
  • 0
    @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?
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!