How to use the differenceInYears function from date-fns

Find comprehensive JavaScript date-fns.differenceInYears code examples handpicked from public code repositorys.

51
52
53
54
55
56
57
58
59
60
exports.differenceInMinutesImpl = dateFns.differenceInMinutes
exports.differenceInMonthsImpl = dateFns.differenceInMonths
exports.differenceInQuartersImpl = dateFns.differenceInQuarters
exports.differenceInSecondsImpl = dateFns.differenceInSeconds
exports.differenceInWeeksImpl = dateFns.differenceInWeeks
exports.differenceInYearsImpl = dateFns.differenceInYears
exports.distanceInWordsImpl = dateFns.distanceInWords
exports.distanceInWordsStrictImpl = dateFns.distanceInWordsStrict
exports.distanceInWordsToNowImpl = dateFns.distanceInWordsToNow
exports.eachDayImpl = dateFns.eachDay
fork icon0
star icon2
watch icon1

+ 16 other calls in file

8
9
10
11
12
13
14
15
16
17
/* eslint-enable */
var dateFns = require('date-fns');
var x = new Date();
var y = new Date(2027, 11, 31, 12, 0);
var temp;
temp = dateFns.differenceInYears(y, x);
var result = temp + ' years ';
x = dateFns.addYears(x, temp);
temp = dateFns.differenceInMonths(y, x);
result = result + temp + ' months ';
fork icon0
star icon0
watch icon0

+ 6 other calls in file

987
988
989
990
991
992
993
994
995
996

const attendance = {
  ...attendanceQuery.dataValues,
  patientBirthDate: formatDate(attendanceQuery.patient.birthDate, 'dd/MM/yyyy'),
  patientAge: attendanceQuery.patient.birthDate
    ? differenceInYears(Date.now(), new Date(attendanceQuery.patient.birthDate))
    : '',
  createdAt: formatDate(attendanceQuery.createdAt, 'dd/MM/yyyy'),
  start: toLocaleTime(attendanceQuery.start, true),
  end: toLocaleTime(attendanceQuery.end, true),
fork icon0
star icon0
watch icon0

130
131
132
133
134
135
136
137
138
139
return {
  discordNick: discordMember ? discordMember.nickname : null,
  isActive,
  isPassive,
  memberSinceInMonths: differenceInMonths(referenceDate, joinDate),
  memberSinceInYears: differenceInYears(referenceDate, joinDate),
  relativeMemberTime: formatDistance(joinDate, referenceDate, { locale: de }),
  membershipNoEqualsAge: parseInt(member.membershipNumber) === birthdayAge,
  membershipNoEqualsBirthDate: referenceDate.getDate() === birthdayAge,
  membershipNoEqualsBirthMonth: referenceDate.getMonth() + 1 === birthdayAge,
fork icon0
star icon0
watch icon1

Other functions in date-fns

Sorted by popularity

function icon

date-fns.format is the most popular function in date-fns (3838 examples)