1// function to convert excel date to normal js date
2excelDateToJSDate(excelDate) {
3 var date = new Date(Math.round((excelDate - (25567 + 1)) * 86400 * 1000));
4 var converted_date = date.toISOString().split('T')[0];
5 return converted_date;
6}
1/use excel-date-to-js
2
3//Description
4//Converts Excel date in integer format into JS date.
5//Dates are stored as numbers in Excel
6//and count the number of days since January 0, 1900 (1900 standard, for mac it is 1904, which means January 0, 1904 is the start date).
7//Times are handled internally as numbers between 0 and 1.
8
9//Install
10//npm install -s excel-date-to-js
11//Usage
12const { getJsDateFromExcel } = require("excel-date-to-js");
13getJsDateFromExcel("42510");
14// 2016-05-20T00:00:00.000Z
1var record_date = Date.parse(item.record_date_string)
2var days = Math.round((record_date - new Date(1899, 11, 30)) / 8.64e7);
3item.record_date = parseInt((days).toFixed(10));
4
5return item;
1function ExcelDateToJSDate(serial) {
2 var utc_days = Math.floor(serial - 25569);
3 var utc_value = utc_days * 86400;
4 var date_info = new Date(utc_value * 1000);
5
6 var fractional_day = serial - Math.floor(serial) + 0.0000001;
7
8 var total_seconds = Math.floor(86400 * fractional_day);
9
10 var seconds = total_seconds % 60;
11
12 total_seconds -= seconds;
13
14 var hours = Math.floor(total_seconds / (60 * 60));
15 var minutes = Math.floor(total_seconds / 60) % 60;
16
17 return new Date(date_info.getFullYear(), date_info.getMonth(), date_info.getDate(), hours, minutes, seconds);
18}
19