How to use the addYears function from date-fns

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

136
137
138
139
140
141
142
143
144
145
                case 'w':
                        return dateTime.addWeeks(date, timeLength);
                case 'M':
                        return dateTime.addMonths(date, timeLength);
                case 'y':
                        return dateTime.addYears(date, timeLength);
                default:
                        throw new Error(`Invalid time unit: ${timeUnit}`);
        }
}
fork icon55
star icon190
watch icon27

29
30
31
32
33
34
35
36
37
38
exports.addMinutesImpl = dateFns.addMinutes
exports.addMonthsImpl = dateFns.addMonths
exports.addQuartersImpl = dateFns.addQuarters
exports.addSecondsImpl = dateFns.addSeconds
exports.addWeeksImpl = dateFns.addWeeks
exports.addYearsImpl = dateFns.addYears
exports.areRangesOverlappingImpl = dateFns.areRangesOverlapping
exports.closestIndexToImpl = dateFns.closestIndexTo
exports.closestToImpl = dateFns.closestTo
exports.compareAscImpl = dateFns.compareAsc
fork icon0
star icon2
watch icon1

+ 16 other calls in file

208
209
210
211
212
213
214
215
216
217
        dateFns.isBefore(props.pageDate, props.lowerLimit)));
const rightDisabled = vue.computed(() => props.upperLimit &&
    (dateFns.getDecade(props.upperLimit) === dateFns.getDecade(props.pageDate) ||
        dateFns.isAfter(props.pageDate, props.upperLimit)));
const previousPage = () => emit('update:pageDate', dateFns.subYears(props.pageDate, 10));
const nextPage = () => emit('update:pageDate', dateFns.addYears(props.pageDate, 10));
return {
    years,
    heading,
    leftDisabled,
fork icon0
star icon0
watch icon0

+ 19 other calls in file

10
11
12
13
14
15
16
17
18
19
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 ';
x = dateFns.addMonths(x, temp);
temp = dateFns.differenceInDays(y, x);
fork icon0
star icon0
watch icon0

+ 6 other calls in file

59
60
61
62
63
64
65
66
67
68

let yearsOk = false;
let seminarsOk = false;
let taikaiOk = !taikai;

if (isAfter(today, addYears(lastDate.val, years))) {
  yearsOk = true;
}

if ((member.seminars?.length || 0) >= seminars) {
fork icon0
star icon0
watch icon0

Other functions in date-fns

Sorted by popularity

function icon

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