locked
Bootstrap Date Picker & Time Picker validation Jquery /Java script RRS feed

  • Question

  • I have two date picker and two time picker

    Below are basic 3 validation which i required

    1- Drop date must be greater then or equal to current date & as well as pick date

    2-Pick Time and drop time must be greater then current time

    3-if pick date is equal to drop date then drop time must be greater then current time.

    Below is my code:

    $(function () {
    var date=new Date();
    date.setDate(date.getDate() - 1);
    $('#txtpickDate').datetimepicker({
    defaultDate:new Date(),
    minDate: date,
    ignoreReadonly: true,
    format: 'MM/DD/YYYY'
    });
    });

    $(function () {
    var date=new Date();
    date.setDate(date.getDate() - 1);
    //date.setDate(date.getDate());

    $('#txtdrpDate').datetimepicker({
    //defaultDate:new Date(),
    minDate: date,
    ignoreReadonly: true,
    format: 'MM/DD/YYYY'
    });
    });

       $(function () {  
                    $('#pickTime').datetimepicker({
                  ignoreReadonly: true,
                        format: 'LT'
                    });
                });

      $(function () {
                    $('#drpTime').datetimepicker({
                    ignoreReadonly: true,
                        format: 'LT'
                    });
                }); 


    Shiv Sharma

    Friday, July 3, 2020 6:09 PM

All replies

  • Hi,

    Use moment js to compare the datetime.

    https://stackoverflow.com/questions/22600856/moment-js-date-time-comparison

    Sample script to construct a datetime for time only picker to do comparison.

    var time = $('#pickTime').data('date');
                var currentDay = moment().format('YYYY-MM-DD');
                var timeAndDate = moment(currentDay + ' ' + time);
                console.log(timeAndDate);

    If you need further help, you  could post in forum as I suggested in your another thread.

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Monday, July 6, 2020 6:31 AM