let span = 6;
let duration = 'months';
let end = start.clone().add(span duration);
The clone part is important, Moment can catch you out by mutating dates.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi all,
I'm using Vue for some frontend stuff and I have a Vue Datepicker to select a start date. I thne have a duration box with 6-months 12 months and 18 months.
So I need to get what the end date will be based on selecting a start date and a duration.
So if I selected 1st Jan and 6 months the end dat should return 1st June.
How would one do this in moment as this is my first time using it to this degree.
let span = 6;
let duration = 'months';
let end = start.clone().add(span duration);
The clone part is important, Moment can catch you out by mutating dates.
Please or to participate in this conversation.