Restrict jquery datetimepicker for past time, if date is current day

Discussion in 'Programming/Scripts' started by Maede, Nov 11, 2019.

  1. Maede

    Maede New Member

    Hi everybody,
    I use jquery date time picker. I want to restrict it for past time. I found "minTime : 0 " as an option but when I apply it, affect all days. ( for example time is 3:00 PM now, I want restrict user to select 2:00 PM but only for today, "minTime : 0 " restrict all days and user can't select 2:00 PM tomorrow) and this is very bad.
    also I try following code :

    let date = new Date();
    let time = date.getHours()+":"+date.getMinutes();

    minTime: time,

    but I got the same result. can anybody help me?

    Thanks in advance.
     
  2. Harsh Shah

    Harsh Shah Banned

    Hi @Maede
    You can restrict time by following way:
    Code:
    $(function () {
                $('#datetimepicker').datetimepicker({
                    minDate : moment(),                         
                });
            });
    Hope this will help you.
    Thank you.
     
  3. Maede

    Maede New Member

    Hi
    Thanks for your help. It only restrict days not hours, I added it as minTime : moment() for restrict hours, but acts as "minTime : 0," and restrict hours of today and all of next days. I want to restrict today hours only.
     

Share This Page