Reputation: 8420
I have this code:
var result = parseInt(moment('07/07/1978', "MM/DD/YYYY").fromNow(true)) > 35
Is there another way using Momentjs
that I can compare the value of moment('07/07/1978', "MM/DD/YYYY").fromNow(true)
with a number without using parseInt (or any way to parse to number)
Upvotes: 0
Views: 28
Reputation: 12919
you can use moment.diff()
to return the difference between two dates in a variety of units
The supported measurements are years, months, weeks, days, hours, minutes, and seconds. For ease of development, the singular forms are supported as of 2.0.0. Units of measurement other than milliseconds are available in version 1.1.1.
const result = moment().diff(moment([1978, 7, 7]), 'years') > 35;
Upvotes: 1