Dan Mishin
Dan Mishin

Reputation: 117

Convert Excel Date string to Unix time in Node.js

I use node-xlsx for parsing Excel file in Node.js but Date cells have strange view before parsing:

in Excel: 01.03.2016 07:44:04
in Node.js before parsing: 42430.32226851852

How I can convert this string 42430.32226851852 to Unix-time format?

Update: Write myself solution that work for me:

var xlsxDate = '42430.32226851852'
var splitDate=xlsxDate.split('.');
var unixTime=new Date(1900, 0, splitDate[0]-1, 0, 0, Math.round(splitDate[1]/1157410)).getTime()/1000
console.log(unixTime)

Where 1157410 is ~1 second

Upvotes: 1

Views: 1710

Answers (2)

Mohammad Nazari
Mohammad Nazari

Reputation: 3025

i use this code to convert Unix-time format:

date = new Date(( parseInt(excelDate) - (25567 + 2))*86400*1000)
unix = date.getTime()

Upvotes: 1

David Webster
David Webster

Reputation: 2321

Another work around is that when you save it to your excel document you save it as a string and not a Date object.

Then you can read it as a string and just wrap it in a new Date()

Upvotes: 0

Related Questions