Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
96
rated 0 times [  103] [ 7]  / answers: 1 / hits: 20469  / 14 Years ago, mon, february 28, 2011, 12:00:00

I need to calculate the number of weeks difference between the chosen date and the current date. I've tried to calculate with weekNumberPicked - weekNumberCurrent, but if the two dates are in different years, the result is incorrect, so I probably need to get it like daysDifference / 7. How should I implement this with the onSelect action?


More From » jquery

 Answers
21

You can use the Datepicker's function getDate to get a Date object.



Then just subtract one date from the other (might want to get the absolute value as well) to get the milliseconds in difference, and calculate the difference in days, or weeks.



$('#test').datepicker({
onSelect: function() {
var date = $(this).datepicker('getDate');
var today = new Date();
var dayDiff = Math.ceil((today - date) / (1000 * 60 * 60 * 24));
}
});

[#93537] Saturday, February 26, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
briannar

Total Points: 354
Total Questions: 103
Total Answers: 101

Location: Japan
Member since Sat, Jun 6, 2020
4 Years ago
briannar questions
Tue, Aug 31, 21, 00:00, 3 Years ago
Sat, Jun 26, 21, 00:00, 3 Years ago
Sat, Jun 20, 20, 00:00, 4 Years ago
Tue, Apr 7, 20, 00:00, 4 Years ago
;