-5

I have to check the given date which is dd/MM/yyyy format that it should fall within 90 days range in java script?

  • Can you provide any code which are you tried to implement? – Ilya Dmitriev Jun 10 '15 at 18:50
  • That's just a statement with a question mark tacked on the end. Have you tried *anything*? Show your code so far and explain what the problem is. I am sure you can find an example of something like this if you'd just search for it. – tnw Jun 10 '15 at 18:59
  • possible duplicate of [How to check if date is within 30 days?](http://stackoverflow.com/questions/6154689/how-to-check-if-date-is-within-30-days) – AGE Jun 10 '15 at 19:05

1 Answers1

0

Take the difference between two dates and divide it by the number of milliseconds in a day.

var difference = (new Date().getTime() - startDate.getTime())/(1000*60*60*24.0)

Find out if the difference between the two dates is more than 90 days

alert Math.abs(difference) < 90 ? "Valid Time" : "Invalid Date Range"

Full working example:

var startDate = new Date('2015-01-01 00:00:00');

var difference = (new Date().getTime() - startDate.getTime()) / (1000 * 60 * 60 * 24.0);

alert(Math.abs(difference) < 90 ? "Valid Time" : "Invalid Date Range");
NickyTheWrench
  • 3,150
  • 1
  • 23
  • 35
Richard Hamilton
  • 25,478
  • 10
  • 60
  • 87