Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

470
Views
How do I escape characters in an Angular date pipe?

I have an Angular date variable today that I'm using the date pipe on, like so:

{{today | date:'LLLL d'}}

February 13

However, I would like to make it appear like this:

13 days so far in February

When I try a naive approach to this, I get this result:

{{today | date:'d days so far in LLLL'}}

13 13PM201818 18o fPMr in February

This is because, for instance d refers to the day.

How can I escape these characters in an Angular date pipe? I tried \d and such, but the result did not change with the added backslashes.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

How about this:

{{today | date:'d \'days so far in\' LLLL'}}

Anything inside single quotes is ignored. Just don't forget to escape them.

over 4 years ago · Santiago Trujillo Report

0

This works for me {{today | date:"d 'days so far in' LLLL"}}

over 4 years ago · Santiago Trujillo Report

0

Then only other alternative to stringing multiple pipes together as suggested by RichMcCluskey would be to create a custom pipe that calls through to momentjs format with the passed in date. Then you could use the same syntax including escape sequence that momentjs supports.

Something like this could work, it is not an exhaustive solution in that it does not deal with localization at all and there is no error handling code or tests.

import { Inject, Pipe, PipeTransform } from '@angular/core';

@Pipe({ name: 'momentDate', pure: true })
export class MomentDatePipe implements PipeTransform {

    transform(value: any, pattern: string): string {
        if (!value)
            return '';
        return moment(value).format(pattern);
    }
}

And then the calling code:

{{today | momentDate:'d [days so far in] LLLL'}}

For all the format specifiers see the documentation for format.

Keep in mind you do have to import momentjs either as an import statement, have it imported in your cli config file, or reference the library from the root HTML page (like index.html).

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!