How to make datepicker choose only a day after the current day

I used the following jQuery code to enter dates in my input fields, to have inputs "from"and "to".

$("#dt1").datepicker({
    dateFormat: "dd-M-yy",
    minDate: 0,
    onSelect: function (date) {
        var dt2 = $('#dt2');
        var startDate = $(this).datepicker('getDate');
        var minDate = $(this).datepicker('getDate');
        dt2.datepicker('setDate', minDate);
        startDate.setDate(startDate.getDate() + 360);
        //sets dt2 maxDate to the last day of 30 days window
        dt2.datepicker('option', 'maxDate', startDate);
        dt2.datepicker('option', 'minDate', minDate);
        $(this).datepicker('option', 'minDate', minDate);
    }
});
$('#dt2').datepicker({
    dateFormat: "dd-M-yy"
});

If I select the first date as 04/19/2017, the second date automatically starts from 04/19/2017. Question: how can I make my second date only the start of counting for one day after the first selected date?

The value will be 04/20/2017 instead of 19 ...

Here you can see all my violin

Hope you can help.

+4
source share
3 answers

You only need this (change onSelectas follows): -

onSelect: function (date) {
    var dt2 = $('#dt2');
    var startDate = $(this).datepicker('getDate','+1d');
    startDate.setDate(startDate.getDate()+1); 
    dt2.datepicker('option', 'minDate', startDate);
    dt2.datepicker('setDate', startDate);
}
+1
source

Try the following:

$('#thedate').datepicker({
    minDate: "+1",
    dateFormat: 'dd-mm-yy'
});
$('#thedate').datepicker("setDate", "+1");

Working script

+2

.

 $(function(){

    $('#FromDate').datepicker({
        minDate: "1",
        dateFormat: 'dd-mm-yy',
            onSelect: function () {
            var dt2 = $('#ToDate');
            var startDate = $(this).datepicker('getDate');
            startDate.setDate(startDate.getDate() + 1);
            var minDate = $(this).datepicker('getDate');
            dt2.datepicker('setDate', startDate);
            dt2.datepicker('option', 'minDate', startDate);
        }
    });


});

$(function(){

        $('#ToDate').datepicker({
                minDate: "0",
                dateFormat: 'dd-mm-yy'
        });

});
0

Source: https://habr.com/ru/post/1675131/


All Articles