Skip to content
Advertisement

MySQL code to convert Excel datetime

Excel’s datetime values look like 42291.60493, which means MySQL sees them as strings and not as dates. Is there a MySQL code that can convert them to MySQL datetime? (i.e. like in MS SQL)

Advertisement

Answer

I can think of 2 solutions:

  1. Convert your dates within excel to a formatted date string that conforms to mysql’s date and time format using text() function within excel.

  2. Convert the number using calculation to date within mysql:

(the expression below may be simplified)

select date_add(date_add(date('1899-12-31'), interval floor(@datefromexcel) day), interval floor(86400*(@datefromexcel-floor(@datefromexcel))) second)
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement