Skip to content

Instantly share code, notes, and snippets.

@gchokeen
Created March 29, 2017 18:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gchokeen/aaee2e1dcc65b6dba60c49e85dc289fe to your computer and use it in GitHub Desktop.
Save gchokeen/aaee2e1dcc65b6dba60c49e85dc289fe to your computer and use it in GitHub Desktop.
Angular 2 custom pipe for age
import {Pipe, PipeTransform} from '@angular/core';
import * as moment from 'moment';
@Pipe({
name: 'age'
})
export class AgePipe implements PipeTransform {
transform(value: Date|moment.Moment, args: string[]): any {
if (!value) return value;
return moment().diff(value, 'years')+" Years";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment