Skip to content

Instantly share code, notes, and snippets.

@TyrfingMjolnir
Forked from christopherscott/ExcelToJsDate.js
Last active August 29, 2015 14:19
Show Gist options
  • Save TyrfingMjolnir/05e2e725a1afc43c78aa to your computer and use it in GitHub Desktop.
Save TyrfingMjolnir/05e2e725a1afc43c78aa to your computer and use it in GitHub Desktop.
/**
*
* Convert Excel dates into JS date objects
* exampleInput: "42090"
* exampleOutput: "Fri Mar 27 2015 01:00:00 GMT+0100 (CET)"
*
* @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 + 2 ) ) * 86400 * 1000 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment