Sidney Sousa
Sidney Sousa

Reputation: 3594

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

I used the following jQuery code to get the dates into my input fields in order to have a "from" and "to" date inputs.

$("#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 choose the first date as 19-04-2017, automatically the second date starts from 19-04-2017 only. Question is: How can I make my second date only start counting one day after the first chosen date?

Meaning it would be 20-04-2017 instead of 19...

Here you can see my entire fiddle

Hope you can help.

Upvotes: 4

Views: 1254

Answers (3)

Sindhoor
Sindhoor

Reputation: 548

Try this. it Will work As u said

 $(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'
        });

});

Upvotes: -1

Death-is-the-real-truth
Death-is-the-real-truth

Reputation: 72299

You need only this (change onSelect like given below):-

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);
}

Upvotes: 1

Mayank Pandeyz
Mayank Pandeyz

Reputation: 26258

Try this:

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

Working Fiddle

Upvotes: 2

Related Questions