I know this is already answered but in case you want something recursive and more generic and not relying on moment fromNow
you could use this function I created. Of course you can change its logic to adjust it to your needs to also support years and seconds.
var createdAt = moment('2019-05-13T14:23:00.607Z');
var expiresAt = moment('2019-05-14T14:23:00.563Z');
// You can also add years in the beginning of the array or seconds in its end
const UNITS = ["months", "weeks", "days", "hours", "minutes"]
function getValidFor (createdAt, expiresAt, unit = 'months') {
const validForUnit = expiresAt.diff(createdAt, unit);
// you could adjust the if to your needs
if (validForUnit > 1 || unit === "minutes") {
return [validForUnit, unit];
}
return getValidFor(createdAt, expiresAt, UNITS[UNITS.indexOf(unit) + 1]);
}