Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
danelooman
Creator
Creator

DateTime to Num rounding error

In JS I am taking in strings like "2020-09-16 08:26:02" and converting them to numbers like "44090.35141203704" 

I am using the function below and on about 25% of my attempts I am getting a rounding error. Has anyone encountered this or done something like this in a mashup/viz before? 

let item = "2020-09-16 08:26:02" 
let parts = item.split(/[?:,| -]+/) 
let date = new Date(parts[0], parts[1]-1, parts[2], parts[3], parts[4], parts[5])
let returnDateTime = 25569.0 + (date.getTime() - date.getTimezoneOffset() * 60 * 1000) / (1000 * 60 * 60 * 24);
return returnDateTime;

 

0 Replies