0

Note: date is in (dd/mm/yyyy) format and this is what, I need to use and I have tried this

function dateCheck(from, to, currentdate) {

    var fDate, lDate, cDate;
    fDate = Date.parse(from);
    lDate = Date.parse(to);
    cDate = Date.parse(currentdate);

    if ((cDate <= lDate && cDate >= fDate)) {
      return true;
    }
    return false;
  }

but in some cases, I don't get the expected output

DarkBee
  • 16,592
  • 6
  • 46
  • 58
Ronak Munjapara
  • 459
  • 5
  • 8
  • 2
    Does this answer your question? [Check if one date is between two dates](https://stackoverflow.com/questions/16080378/check-if-one-date-is-between-two-dates) – DarkBee Jul 07 '22 at 06:02
  • 1
    "dd/mm/yyyy" is not a standard date format: [What are valid Date Time Strings in JavaScript?](https://stackoverflow.com/q/51715259) – VLAZ Jul 07 '22 at 06:02
  • 1
    If you format both dates as `yyyymmdd` you can compare them as strings and check if the given date is **>=** than `rangeStart` while at the same time **<=** than `rangeEnd`. – IVO GELOV Jul 07 '22 at 06:50
  • @VLAZ—re "*dd/mm/yyyy" is not a standard date format*". It is, globally, an extremely common format, just that most (all?) ECMAScript date parsers assume the peculiar US m/d/y format. – RobG Jul 07 '22 at 11:08
  • @RobG I'm not saying that's not a format that is used ever. I'm saying it is not valid as per the ECMAScript standard. Hence you get non-standard (implementation-dependent) behaviour. Because the spec doesn't say how these dates should be handled. – VLAZ Jul 07 '22 at 11:12
  • See [*Convert dd-mm-yyyy string to date*](https://stackoverflow.com/questions/7151543/convert-dd-mm-yyyy-string-to-date) – RobG Jul 07 '22 at 13:41

0 Answers0