Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert decimal serial number from excel to mysql correctly

I have a column in Excel csv with values like this

42973.74257

I want to convert it to MySQL date time by using:

DATE_ADD('1900-01-01', INTERVAL (42973.74257*60*60*24) second) as date

However, it would give me an incorrect result

2017-08-28 17:49:18.048000

while the correct result should be

8/26/2017 5:49:18 PM

It add 2 more days to the result. As I have around 1M rows so I would not know if all the results would be incorrect.

Do you guys have any better way to convert serial numbers from excel to mysql?

Thanks,

H

like image 204
Hai Vu Avatar asked Dec 19 '25 11:12

Hai Vu


1 Answers

Your answer is wrong by two days.

One of those days is because it actually treats 1st of Jan 1900 as 1, not 0 (ref).

According to this blog post, it's off by another day because Excel incorrectly treats the year 1900 as a leap year for legacy compatibility reasons.

If you subtract 2 from the value before passing it into your formula, it should work.

like image 194
David P Avatar answered Dec 21 '25 03:12

David P



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!