0

Is it possible to pass a piped date as an argument for a function?

I am thinking of something along the lines of...

  • A variable date: string that will be assigned a value passed from a datepicker
  • The date picker currently outputs date values in the format:

    Fri Feb 09 2018 00:00:00 GMT+0000 (GMT Standard Time)

  • It is possible to display the date in binding with use of date | date:'yyyy-MM-dd'

I am wanting to pass into a function, that piped date - something like:

someFunction(date | date:'yyyy-MM-dd');

Is there any way that this could be possible?

Or will I have to pass the original long date into a function, mutate it and then use it?

physicsboy
  • 4,011
  • 10
  • 45
  • 85

1 Answers1

0

I have since found a way to just JS it - How do I get a date in YYYY-MM-DD format?

This splits the date and then recombines it into a string:

onSelect(theDate: Date): void {

    var yyyy = theDate.getFullYear().toString();
    var mm = (theDate.getMonth()+1).toString();
    var dd  = theDate.getDate().toString();

    var mmChars = mm.split('');
    var ddChars = dd.split('');

    var dateString = yyyy + '-' + (mmChars[1]?mm:"0"+mmChars[0]) + '-' + (ddChars[1]?dd:"0"+ddChars[0]);


    this.meetingService.getMeetingsByDate(dateString);
  }
physicsboy
  • 4,011
  • 10
  • 45
  • 85