0

I’m aware of doing this with a library in order to find the current date and use an integer to find the next date, but I’m trying to find the number of days between two date strings in this format

Date1.value = ‘2022-02-22’;
Date2.value = ‘2022-03-01’;

Is there a library I need for this or could I do it with vanilla JS

Geoff_S
  • 4,917
  • 7
  • 43
  • 133
  • What is the expected result? What are `Date1` and `Date2`? If these are ``s, simply do `Date2.valueAsDate - Date1.valueAsDate`. – Sebastian Simon Feb 08 '22 at 16:38

1 Answers1

1

checkout https://github.com/you-dont-need/You-Dont-Need-Momentjs#difference

let a = Math.ceil(
  (new Date('2022-03-01') - new Date('2022-02-22')) / 1000 / 60 / 60 / 24
);

console.log(a)
cmgchess
  • 7,996
  • 37
  • 44
  • 62