📆 Convert between Excel and JS dates
This script takes into consideration the Leap-Year bug and the date difference between 1900 and 1904 Excel Date Systems.
Usage
// You can verify these results with the example at:// https://docs.microsoft.com/en-us/office/troubleshoot/excel/1900-and-1904-date-system const toExcelDate = toExcelDate;const fromExcelDate = fromExcelDate; const jul = 'jul 5 1998'; ; // 35981 (1900 date system) ; // 34519 (1904 date system) ; // "Sun, 05 Jul 1998 00:00:00 GMT" ; // "Sun, 05 Jul 1998 00:00:00 GMT"
API
Date
fromExcelDate(excelDate, date1904): Param | Type | Required | Description |
---|---|---|---|
excelDate | number |
yes | An integer number representing a date in Excel. |
date1904 | boolean |
no | Set this to true if the date is encoded in 1904 Date System. This is the default format for Excel in MacOS.If you're using SheetJS you can check which system the file is using by calling wb.Workbook.WBProps.date1904 |
number
toExcelDate(date, date1904): Param | Type | Required | Description |
---|---|---|---|
date | Date |
yes | Date to encode into Excel format. |
date1904 | boolean |
no | If true , the date will be encoded to 1904 Date System. This is the default format for Excel in MacOS.If you're using SheetJS you can check which system the file is using by calling wb.Workbook.WBProps.date1904 |
Credits
Raschid JF. Rafaelly