'How can I get diff using dayjs from date to now type of array?
I want to know how can i get diff using dayjs from date to now type of array?
and i wanna make locale function too.
// if i input 2021-03
// output will be [2021-04, 2021-05, ... 2022-05]
const createdAt = "2021-03";
const selectableMonths = Array(12)
.fill(0)
.map((_, index) => {
const dateText = dayjs().subtract(index, 'months');
return {
text: i18next.t("date_format",{
val: new Date(dateText.format("YYYY-MM")),
fotmatParams: {
en: {
short: {
year: 'numeric',
month: 'short',
},
long: {
year: 'numeric',
month: 'short',
day: 'numeric',
},
},
ko: {
short: {
year: 'numeric',
month: 'long',
},
long: {
year: 'numeric',
month: 'long',
day: 'numeric',
},
},
},
}
),
value: {
from: dateText.format('YYYY-MM'),
to: dateText.add(1,'months').format('YYYY-MM'),
}
}
})
.filter((v) => dayjs(v.value.from).isSameOrAfter(dayjs(teamCreatedAt)));
this is my code..
how can i get a array like [2021-04, 2021-05, ... 2022-05]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
