Skip to content

Instantly share code, notes, and snippets.

@christopherscott
Created May 24, 2012 16:40
Show Gist options
  • Save christopherscott/2782634 to your computer and use it in GitHub Desktop.
Save christopherscott/2782634 to your computer and use it in GitHub Desktop.
Convert Excel date values to JavaScript date objects
// Convert Excel dates into JS date objects
//
// @param excelDate {Number}
// @return {Date}
function getJsDateFromExcel(excelDate) {
// JavaScript dates can be constructed by passing milliseconds
// since the Unix epoch (January 1, 1970) example: new Date(12312512312);
// 1. Subtract number of days between Jan 1, 1900 and Jan 1, 1970, plus 1 (Google "excel leap year bug")
// 2. Convert to milliseconds.
return new Date((excelDate - (25567 + 1))*86400*1000);
}
@bpiroman
Copy link

bpiroman commented Sep 8, 2024

legend!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment