1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

How to set input format of DatePipe

Discussão em 'Angular' iniciado por Charmi, Setembro 30, 2024.

  1. Charmi

    Charmi Guest

    I want to just display month and year i.e. 09/24.

    Now, I am receiving list of bills that are generated in last 3 months through an API where bill date format is 'dd-mm-yyyy'.

    billDataList = [
    {'id' = 101, 'bill_date': '17-08-2024'},
    {'id' = 102, 'bill_date': '02-08-2024'},
    {'id' = 103, 'bill_date': '26-09-2024'}
    ]


    In html template, list is on loop to display the id and date

    <ng-container *ngFor="let bill of billDataList>
    <div class="bill-row-small">
    <span>{{bill['id']: {{bill['bill_date'] | date:'MM/yy'}}</span>
    </div>
    </ng-container>


    But it throws error:


    InvalidPipeArgument: 'Unable to convert "28-09-2024" into a date' for pipe 'DatePipe'
    ​

    This is may be because bydefault DatePipe takes format as 'medium' i.e. 'MMM d, y, h:mm:ss a'.

    How to set input format of date as 'dd-mm-yyyy'

    Continue reading...

Compartilhe esta Página