将存储为varchar的十进制转换为datetime [英] Convert decimal stored as varchar to datetime

查看:199
本文介绍了将存储为varchar的十进制转换为datetime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经继承了一个日期列类型为 Varchar 的MySQL数据库。

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

该列包含十进制字符串。例如: 41143.646585648

The column contains decimal strings. For example: 41143.646585648.

我将如何将其转换为DateTime格式?

How would I go about converting this into DateTime format?

推荐答案

您需要知道的是原始开发人员定义为零值的日期。那么这是一个简单的事情,添加到该日期的整数天数,然后将小数部分乘以86400获得秒,并进行算术以确定小时,分钟和秒。

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.

这篇关于将存储为varchar的十进制转换为datetime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆