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

207
Views
How do you find the difference in dates between a date selector and todays date with an error message if date is less than a certain amount of days

I am a very new learner and have been trying to learn as I go and I am completely stumped. I need to do the following and I cannot figure it out.

  1. You have to write a function called “dateDiff” that accepts one date parameter and returns the number of days between the birthday provided and the current date.

  2. Print “fname lname you have been breathing for ### days!” where ### is the number returned by your dateDiff() function. Remember to convert milliseconds to days and only return the integer(whole) number of days.

If the number of days is less than (365*18) then print “You are probably not old enough to take this class!”

Now, I have already created the following: (User id, Fname, Lname, Birthday,) as part of a login screen. Below is the code that I have written so far. Please be kind. This is my first crack at javascript.

Thank you!

HTML

<label for="birthday">Birthday:</label><br><br>
    <input class="form-control" type="date" name="datestart" value="" class="datepicker" required="" 
        placeholder="birthday" oninvalid="this.setCustomValidity('Invalid Birthday')">

JS

var d1 = new Date();
    var d2 = new Date() 

    var diff = d2.getTime() - d1.getTime();   
    var daydiff = diff / (1000 * 60 * 60 * 24);  
    document.write(" Total number of days between <b> " + d1 + " </b> and <b> " + d2 + " </b> is: <b> " + daydiff + " days </b>" ); 
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!