You must Sign In to post a response.
  • Category: JavaScript

    Please tell me how to disable previous date from current date.

    Hi All,
    I am using this javascript but this is not correct working.

    please tell me how to disable previous date from current date.

    <script type="text/javascript">
    //$(document).ready(function () {
    // $(".dDate").datepicker({
    // dateFormat: 'dd/mm/yyyy',
    // firstDay: 1,
    // numberOfMonths: 1,
    // minDate: '0',
    // onSelect: function () {
    // $(this).trigger("onchange", null);
    // }
    // });
    //});

    $('.dDate').datepicker(
    {
    onClick: function (target, cell, date, data) {
    target.val(date.getFullYear() + '-' +
    date.getMonth() + '-' +
    date.getDate());

    if (data != null) {
    alert(data.message + '\n' + date);
    }
    }
    }
    );

    </script>
  • #747485
    Hai Atul,
    it will be easy if you use JQuery calendar as it will have the built-in properties and you can easily set it as below:

    $(function() {
    $( "#calendardatepicker" ).datepicker({
    numberOfMonths: 1,
    showButtonPanel: true,
    minDate: '0'
    });
    });

    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #747486
    Hi Atul,

    You can disable past days in javascript by this way-
    code-
    <script type="text/javascript">
    $(function () {
    var date = new Date();
    var currentMonth = date.getMonth(); // current month
    var currentDate = date.getDate(); // current date
    var currentYear = date.getFullYear(); //this year
    $("#<%= tbxRequestDeliveryDate.ClientID %>").datepicker({
    changeMonth: true, // this will allow users to chnage the month
    changeYear: true, // this will allow users to chnage the year
    minDate: new Date(currentYear, currentMonth, currentDate)

    });
    });
    </script>
    <asp:TextBox ID="tbxRequestDeliveryDate" runat="server" CssClass="text"></asp:TextBox>
    Please add below JS and Css to work it properly
    jquery-1.4.1.min.js
    jquery.ui.core.js
    jquery.ui.datepicker.js
    jquery-ui-1.8.8.custom.css
    you can go through it for more details-http://www.codeproject.com/Tips/231127/jQuery-UI-datepicker-disable-days-in-a-week

    Thanks,
    Ashutosh Jha
    http://tricksroad.com

  • #747518
    Hi,

    You can use the minDate option in your datepicker initialization to disable the previous date. Please refer below code.

    $(function() {

    $('#datepicker').datepicker({minDate: 0});
    });


    Regards,
    Asheej T K

  • #748024
    Hi,

    Try setting the mindate to ). This will disbale the previous dates

    $( "#datepicker" ).datepicker({ minDate: 0});

    Thanks,
    Vetri


  • Sign In to post your comments