First of all, let’s import momentJS to our project:
import * as moment from 'moment';
Now that we’re ready to use the moment() method we can use the following snippet:
const now = moment(new Date()); //todays date const end = moment(this.fecha, 'DD/MM/YYYY'); // another date const duration = moment.duration(end.diff(now)); const days = Math.round(duration.asDays());
Note that I’m using Math.round() that is because the return of moment.duration() could be with fractional digits so in order to just get days we use it.