Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

287
Views
Datetime-local limit past and future date JavaScript

I have 2 inputs for datetime-local (start-time & end-time). I want to limit the start date to select only the last 72 hours which I did but i cannot restrict future time. I only want today and only last 3 days. And for end time only today and next 3 days. This is my code:

<input type="datetime-local" name="start_timestamp" id="start_timestamp" required>
            
<input type="datetime-local" name="end_timestamp" id="end_timestamp" required>

<script>
    //Do not let to select START TIME  in the PAST
    var today = new Date();
    var past = new Date(today.setDate(today.getDate() - 3)).toISOString().slice(0, 16);
    

    document.getElementsByName("start_timestamp")[0].min = past;
    document.getElementsByName("start_timestamp")[0].max = today;
</script>


            
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

See here a possible fix.

<input type="datetime-local" name="start_timestamp" id="start_timestamp" required>
            
<input type="datetime-local" name="end_timestamp" id="end_timestamp" required>




<script>
    //Do not let to select START TIME  in the PAST
    let today = new Date();
    let past = new Date(today.setDate(today.getDate() - 3)).toISOString().slice(0, 16);
    today = new Date().toISOString().slice(0, 16);

    document.getElementsByName("start_timestamp")[0].min = past;
    document.getElementsByName("start_timestamp")[0].max = today;
    
    document.getElementsByName("end_timestamp")[0].min = past;
    document.getElementsByName("end_timestamp")[0].max = today;
    
</script>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!