Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
100
rated 0 times [  103] [ 3]  / answers: 1 / hits: 43820  / 12 Years ago, wed, october 10, 2012, 12:00:00

I'm trying to compare two datepicker dates and see if they are more than 7 days apart.



How would I do this?



I would normally just see if their difference is greater than 7, but that won't account for months and such.



Here is my code:



var datepickerBegin = $(#datepicker_start).val();
var datepickerEnd = $(#datepicker_to).val();

if (datepickerBegin - datepickerEnd > 7) {
alert('more than a week apart!')
}


Any tips??


More From » jquery

 Answers
83

Use $(#datepicker_xxx).datepicker(getDate) to get the picked date as a Date. Then it's just a matter of



end - begin > 7 * 86400 * 1000

[#82633] Tuesday, October 9, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
myrap

Total Points: 407
Total Questions: 105
Total Answers: 109

Location: Cambodia
Member since Thu, Oct 7, 2021
3 Years ago
myrap questions
Tue, Feb 8, 22, 00:00, 2 Years ago
Wed, Jan 15, 20, 00:00, 4 Years ago
Thu, Oct 24, 19, 00:00, 5 Years ago
Thu, Oct 3, 19, 00:00, 5 Years ago
Mon, Aug 12, 19, 00:00, 5 Years ago
;