Problem for spaced dates

hello i just wanted to spaced the fields date two days


I found it but it does not work

function addDays(days) {
var date = new Date(); // today
date.setDate(date.getDate() + days); return date;
}
$w.onReady( function () {

let query = wixLocation.query;

console.log(query.param); 

  $w("#datePicker1").minDate = addDays(0); 
  $w("#datePicker2").maxDate = addDays(2);  

});

thank you for your help

Hi

Not sure what you are trying to achieve, but note that the Date object represents a number of milliseconds.
So if you want to add 2 days to a date, you need to add : 2 * 24 * 3600 * 1000 to the date.

Hi my friend
sorry for not having answered earlier thank you for the return but I am a beginner in the coding in your opinion I should write it like that?

function addDays(days) {
var date = new Date(); // today
date.setDate(date.getDate() + days); return date;
}
$w.onReady( function () {
let query = wixLocation.query;
console.log(query.param);
$w(" #datePicker1 “).minDate = addDays(0);
$w(” #datePicker2 ").maxDate = addDays( 2 * 24 * 3600 * 1000 );
});

HI Omar:

Try the following code.

You can create a date object in one line by taking the guidance from Jerome using the Date.now() inside the Date constructor. So your addDays function would look like…

function addDays(days) {
    return new Date(Date.now() + days*24*60*60*1000); // today  
}

Hello my friends
thank you it works, however I will need when the first date is select the second date jumps two days may I solicitude your knowledge

I put the coding that I realized thanks to your help

Hi Omar:

You can change the function and give it a date that you get as your baseline. Then just add differences to that starting point.

So something like this (if I am understanding you correctly).

function addDays(baselineDate, days) {
  return new Date(baselineDate + days*24*60*60*1000);
}

...
let baselineDate = Date.now(); 
$w('#datePicker1').minDate = addDays(baselineDate, 0);
$w('#datePicker1').maxDate = addDays(baselineDate, 7);
$w('#datePicker2').minDate = addDays(baselineDate, 2);
$w('#datePicker2').maxDate = addDays(baselineDate, 7);

Hope this helps

Hello my dear friend

I tried your coding but it did not work

example if I select (datepicker1) the date 11/02/2018 automatically in (datepicker2) I would have 13/02/2018 the minimum date of selection

thanks again for the time allotted

Omar:

Can you share the page or a screen shot? I am not completely sure what you are trying to do.

Can you also give an example of what you are expecting to see?
For example The code above will (based on your example) populate two date pickers.
datePicker1 will show a calendar with the only selectable dates being today and all the days up to a week from today (7 days).
datePicker2 will show a calendar with the only selectable dates two days after today and all the days up to 9 days from today (2 days + 7 days).

If that is not what you are expecting then you need to share more of your needs with a specific example.

I hope this makes sense.

hello

hello so here are my examples I’m a laundry at home and when the customer orders there is a delay of washing process, that’s why we have two date one for the recovery and one for delivery, when customer chooses its date of recovery it can not be selected the same day because that would pose problem for our cleaning period that is why I must imposed them minimum two days via the date picker I put you an example more the link of the site which I created

https://omarbiddiche.wixsite.com/monsite-2/reservation


thanks again

Hi Omar:

I think I understand now.

What you are saying is that when the date for recovery (collection) is selected then you want to automatically set the date for delivery to be two days later.

So if the customer chooses Lundi then you want to offer delivery starting on or after Mecredi.

If this is the case then I would disable $w(" #datePicker2 “) using $w(” #datePicker2 “).disable(); in your $w.onReady() function. Then wait for the customer to change the value of $w(” #datePicker 1") using the onChange handler. In the onChange handler I would enable the delivery datepicker and use the selected date from $w(" #datePicker 1") to configure datepicker 2

$w.onReady(() => {
    $w("#datePicker2").disable(); // Don't allow input until the collection date is set
    $w("#datePicker1").minDate = addDays(Date.now(), 0); // We can collect from today
    
    // When a collection date is set we can enable the delivery date
    $w("#datePicker1").onChange((event) => {
        let baselineDate = $w("#datePicker1").value;
        $w("#datePicker2").minDate = addDays(baselineDate.valueOf(), 2);
        $w("#datePicker2").enable();
    }
});

function addDays(baselineDate, days) {
    return new Date(baselineDate + days*24*60*60*1000);
}

I don’t think you need to worry about setting the maxDate value.

Hope this helps
Steve

Hello Mr Croppe Steeve

that’s exactly that I thank you a thousand times for your patience in my work and proffessionalism,
Thanks again

2 Likes