-1

I've inherited a MySQL database with a date column type of Varchar.

The column contains decimal strings. For example: 41143.646585648.

How would I go about converting this into DateTime format?

4

2 回答 2

0

All you need to know is the date the original developer defined as the value zero. Then it's a simple matter of adding the integer number of days to that date, then multiplying the fractional part by 86400 to get seconds and doing the arithmetic to determine the hour, minute and second.

If you have a row where you know the actual date and the stored value you can determine the zero date easily by subtraction.

于 2013-01-10T00:27:54.270 回答
0

You could string replace the dot, but the remaining count of numbers is to high for a unix timestamp. I don't know how the date was converted to decimal. Maybe you should split your string rather than string replace.

Maybe this code gives you some ideas for a solution:

#SELECT FROM_UNIXTIME(REPLACE('41143.646585648', '.', '')); # Does not work due to wrong amount of numbers in string

SELECT FROM_UNIXTIME(REPLACE('13577.77916', '.', '')); # works
于 2013-01-10T00:35:53.870 回答