I want to store the value of a datePicker in WixCO

2019-06-05 00:01发布

问题:

Based on this Supplied Code,

$w.onReady(function () {
    //TODO: write your page related code here...
    const startFromDays = 4;
    const endAtMonths = 9;
    const today = new Date();
    let startDate = new Date(today);
    let endDate = new Date(today);

    startDate.setDate(startDate.getDate() + startFromDays);
    endDate.setMonth(endDate.getMonth() + endAtMonths);

    $w.onReady(function () {
        $w("#datePicker1").minDate = startDate;
        $w("#datePicker2").maxDate = endDate;
    });
});

I need help to find the difference between the endDate and the startDate and output it as Text. Knowing the fact that some start dates can be of the Eg: 26th of Feb and end Date can fall on 3rd March.

This Code is been run on Wixcode, where the dates are used as a Date-picker user input. Thank you.

回答1:

Start by getting the difference between the two dates using something like what is described in this post.

Then, use that number to populate a text field that you've added to your page.

So, assuming you have a datediff() function declared:

const diff = datediff(startDate, endDate);
$w("#text1").text = diff.toString();