0

I am developing a site where i am using jQuery-UI datepicker, the problem is i have to select all dates and put it into an array when the user select a start date and end date using a aingle jquery UI datepicker.

i checked the jQuery-UI documentation but found nothing that solve my problem.

I want date-range to be picked up like this.

enter image description here

i have to use jQuery-UI, so any useful idea will be appreciated,

Thanks

2 Answers 2

1

you can use this method:

1.The user clicks the 2 dates

2.You save them as two variables(startDate,endDate)

3.you make a loop:

var numberOfDaysToAdd=0
var startDate;
var endDate;
var dateCheck=startDate;
var DatetoAddInArray = startDate;
var  array = [];
while(DatetoAddInArray!=endDate){
    //every time you check if the date is equal to the endDate
    //if  is not you add it in the array with the dates and then
    //you increase the index.
    //the while loop ends when you find the end  Date
    //You can change your code to add or not the start and the end dates
    numberOfDaysToAdd++;
    DatetoAddInArray.setDate(DatetoAddInArray.getDate()+numberOfDaysToAdd);
    array[numberOfDaysToAdd-1]=DatetoAddInArray;
 }

The above could be an easy way to store all the dates from the start to the end date.

(!) If the datepicker allows the user to click a startDate and then click a endDate that is before the startDate, you have to alert a message to the user to select a correct range.

Thanks.

Sign up to request clarification or add additional context in comments.

Comments

1

I created datepicker like this, so no need for more answers. Thanks

Here is working Fiddle

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.