skip to Main Content
var timewsd = document.getElementById("current_datetime").value ;
            var currentdate = "";





            let roundDate = (date = new Date(timewsd), roundToMinutes = 60) => {
                const ms = 1000 * 60 * roundToMinutes;
                return new Date(Math.ceil(date.getTime() / ms) * ms);
            };

            var current_time = new Date(timewsd).getHours()+":"+new Date(timewsd).getMinutes();

            const date = new Date(timewsd);

            // if(current_time > '16:30'){
            //     currentdate =  setDate(timewsd.getDate() + 1);
            // }else{
            //     currentdate = document.getElementById("current_datetime").value;
            // }



            $("#kt_datepicker_2").flatpickr({
                minDate: "today",
                minuteIncrement: 1,
                enableTime: true,
                minTime :current_time
            });

However when selecting a future date the time limits to the current time for the futiure date too.

https://flatpickr.js.org/examples/

2

Answers


  1. Instead of using minDate: "today" replace it with minDate: new Date() & also remove minTime and you will get your desired output.

    Below, I have provided a live example for your reference.

    <!DOCTYPE html>
    <html>
    <head>
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
    </head>
    <body>
        <h1>Select a Date and Time</h1>
        <input type="text" id="datepicker" placeholder="Select date and time">
        
        <script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
        <script>
            flatpickr("#datepicker", {
                enableTime: true,
                minuteIncrement: 1,
                minDate: new Date()
            })
        </script>
    </body>
    </html>
    Login or Signup to reply.
  2. If you want to disable past time and past date both then follow this code:

    <!DOCTYPE html>
    <html>
    
    <head>
        <!-- flatpicker CSS CDN  -->
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
    </head>
    
    <body>
    
        <h4>Select a Date and Time</h4>
        <input type="text" id="datepicker" placeholder="Select date and time">
    
        <!-- flatpicker JS CDN -->
        <script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
        <script>
            const now = new Date();   // get current date and time
            var currentHour = now.getHours();   // get current hours
            var currentMinute = now.getMinutes();   // get current minutes
            flatpickr("#datepicker", {
                enableTime: true,
                minuteIncrement: 1,
                minDate: new Date(),
                minTime: `${currentHour}:${currentMinute}`,
            });
        </script>
    </body>
    
    </html>

    If you want to disable the date only then remove minTime element from a flatpicker config.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search