Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
171
rated 0 times [  178] [ 7]  / answers: 1 / hits: 16077  / 11 Years ago, thu, october 10, 2013, 12:00:00

I'm using jquery datepicker in order to get 2 dates. In my case I have to get the date in this format d-M-y. I'm using it in order to be able to insert the values into an oracle database without any formating. The problem is that I need to calculate the months between 2 dates. For example: 1-Oct-13 - 30-Oct-16.



Here is how I'm getting the dates in my js:



LastAssimDatePicker = (function() {
$( #lastAssimilationDate ).datepicker({
yearRange: -20:+100,
changeMonth: true,
changeYear: true,
dateFormat: d-M-y
});
}),

LastAssimDateOverPicker = (function() {
$( #lastAssimilationDateOver ).datepicker({
yearRange: -20:+100,
changeMonth: true,
changeYear: true,
dateFormat: d-M-y
});
}),


The above dates are assigned to 2 variables - lastAssimilationDate and LastAssimDateOver



The problem is that I really can't find a way to calculate the months between the 2 dates and I already lost about 2 hours on it. I'm pretty sure that there will be an easy solution, but as a beginner, I'm not able to spot it. I know that there are simmilar topics here, but I can't get it working, or it does not fit on my issue.


More From » jquery

 Answers
3

Since you mentioned that you are not supposed to change the format I have a solution for you.



With the help of @T.J. Crowder's Answer, I done this



d1 = new Date($( #lastAssimilationDate ).val());
d2 = new Date($( #lastAssimilationDateOver).val());
alert(monthDiff(d1, d2));


Check this JSFiddle



Not sure Nan is popping, but I am able to see difference.



enter


[#75103] Wednesday, October 9, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ryderalfonsos

Total Points: 655
Total Questions: 88
Total Answers: 91

Location: Nauru
Member since Thu, Feb 2, 2023
1 Year ago
ryderalfonsos questions
Mon, Sep 9, 19, 00:00, 5 Years ago
Wed, Feb 13, 19, 00:00, 5 Years ago
Tue, Feb 12, 19, 00:00, 5 Years ago
Fri, Dec 28, 18, 00:00, 6 Years ago
;