Operations with dates in javascript

I hope you guys can help me. I’m developing a shopping page about online courses in Elementor. These courses start every 2 months and I want to add a feature that changes the price when there are only 19 or less days left to purchase the course before it starts. I managed to solve the problem only for certain cases, for example: The course begin on february 28th and todays date is february 17th. So by using the “new Date()” object and then adding the .getDate() method, I got the current day. Then, to grab the course date, I had to use the method parseInt(“28th february”), (I’m Spanish so the number comes first). Once I had both dates I wrote an if statement saying:

if ((courseDate – currentDate) <= 19) {
Do this…
}

It works if boths dates are in the same month… But, for example, if the course begins the next month, on march 22th, it will also evaluate to true, but there are actually more than 19 days left to purchase… Any ideas about how can I solve it? I appriciate your help and time guys