Juliver Galleto
Juliver Galleto

Reputation: 9037

get the end date base from the given start date

Im using moment js and what I want is get the calculated month, year and day from the specified start month, day and year within a year e.g. if Jan 1, 2015 is the start date then it should be Dec 31, 2015, any ideas, clues, suggestion, how to do it?

Below is 2 input fields that has an identity id of 'startdate' and 'enddate'

<input type="text" id="startdate" value="Jan 1, 2015" />
<input type="text" id="enddate" />

so if user pick from a datepicker from an input field that has an id of 'startdate' then (assume i used datepicker that output a format of MMM,DD,YYYY) the input field that has an id of 'enddate' should contains the end date (month, days, year) base from the started date within the current year of the start date (assume Jan 1, 2015, then end date is Dec, 31, 2015).

$(document).ready(function(){
    $("#startdate").change(function(){
        $("#enddate").val();
    });
});

Upvotes: 1

Views: 442

Answers (1)

Rahul Tripathi
Rahul Tripathi

Reputation: 172458

You can try to use endof like this:

var endDate = moment(startDate).endOf('year');

However if you are looking to add 1 years to the start date then you can try this:

var endDate = moment(startdate, "DD-MM-YYYY").add('days', 365).format("DD/MM/YYYY");

Upvotes: 0

Related Questions