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

317
Views
Validate 2 datetime-local in javascript/jQuery

I have a form where I want to validate 2 datetime-local a start-date and an end-date. What I want is to not let the user select a start date older than 48 hours (browser time) and the end date to not be set in past. This is my code till now:

<form>
  <tr>
     <td>
      <input type="datetime-local" name="start_timestamp" id="start_timestamp" required>
     </td>
                
     <td>
      <input type="datetime-local" name="end_timestamp" id="end_timestamp" required>
     </td>
 </tr>
</form>

And the js so far (PS: I am not very good at js)

var start_date = document.getElementById("start_timestamp").value;
var end_date = document.getElementById("end_timestamp").value;
var now = new Date().toDateString();

    if (end_date < start_date) {
        return 1;
    }
    else {
        return 0;
    }

    if (start_date < now-2) {
        return 1;
    }
    else {
        return 0;
    }
about 4 years ago · Juan Pablo Isaza
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!