My versions of João Durante's code. I had trouble with timezone offset calculation that caused the float value to stack with time, thus switched to using straightforward UTC. Also, dates in the year 1900 weren't calculated properly. This code was tested with start and end dates of months in 1900, 2000, 2010, and maximum date value for Excel (9999-12-31)
function JSDateToExcelDate(year, month, day) {
let date = new Date(Date.UTC(year, month - 1, day));
let ExcelSerialNumber = 25569.0 + (date.getTime() / (1000 * 60 * 60 * 24));
if (year == 1900 && month == 2 && day == 29) {
return 60
}
if (ExcelSerialNumber <= 60) {
return ExcelSerialNumber-1;
}
return ExcelSerialNumber;
}