Click here to Skip to main content
15,893,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
A fiscal year is having 1-52 weeks. All these weeks are displaying in a dropdownlist (1 to 52). And i have start date and end date text boxes. Selected 34 weeks from dropdown list. When I selected start date, the end date has to calculate based on the selected weeks.i.e., I have to populate end date with a difference of 34 weeks from start date
Example :1
No.Of Weeks: 34
Selected Start Date: 10/27/2016
As per the first 2 selections my calculated end date has to be 06/22/2017. But the jquery is showing 06/23/2017

Example :2
No.Of Weeks: 21
Selected Start Date: 10/01/2016
As per the first 2 selections my calculated end date has to be 02/25/2017. But the jquery is showing 02/28/2017

What I have tried:

below is my code:
JavaScript
var weeks = $("#WeekCount").val();
var stDate = new Date($("#txtStartDate").val());
var enDate= new Date(stDate.getFullYear(), stDate.getMonth() + 1, stDate.getDate() + (weeks * 7));
enDate= enDate.getMonth() + "/" + enDate.getDate() + "/" + enDate.getFullYear();

Can someone help what is wrong in my code.?
Posted
Updated 9-Nov-16 2:17am
v2
Comments
Karthik_Mahalingam 9-Nov-16 8:18am    
what is the formula you are using to calculate?

1 solution

Just Maths. Try this:
<script>
function getDateOfWeeksAway(w, d, m, y) {
    var numOfDaysAway = d + w * 7;
    return new Date(y, m-1, numOfDaysAway);
}
alert(getDateOfWeeksAway(34, 27, 10, 2016));
</script>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900