只需将mysql数据库中的5位数字转换为日期 [英] Simply convert 5 digit number in mysql database to a date

查看:3892
本文介绍了只需将mysql数据库中的5位数字转换为日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在网路上看到这个答案,但不明白所有写的东西。我尝试从unix_timestamp()执行,但它返回错误的日期。
我所做的是将一个xls文件导入数据库。它将日期转换为5位数字。
有简单的方法吗?任何帮助都会很棒。
这是我试过的。我尝试将excel文件中的日期格式更改为YYYY-MM-DD,而这没有起作用。

解决方案

Excel值,请尝试:

  select date('1899-12-30')+ interval< number>天

例如:

 选择日期('1899-12-30')+间隔40000天

返回2009年7月6日,就像在Excel中一样。



换句话说,您可以将值作为一个整数,然后在SQL中进行转换。我实际上有点惊讶,因为Excel的0日期本质上是1900年1月0日,即1899年12月31日。我怀疑有一个问题1900年缺乏闰年.2006年2月29日,Excel的价值为60。这是有趣的,我没有意识到Excel有这个错误。



所以,上述代码适用于所有大于61的值。


I have been looking all over the web for this answer but dont understand all the things that were written. I try to do the from unix_timestamp() but it returns the wrong date. What I have done is import a xls file into the database. It converted the date to a 5 digit number. Is there a simple way? Any help would be great. This is what I have tried. I tried changing the date format in the excel file to YYYY-MM-DD and this did not work.

解决方案

To go from Excel values, try this:

select date('1899-12-30') + interval <number> days

For instance:

select date('1899-12-30') + interval 40000 days

Returns July 6, 2009, just as it does in Excel.

In other words, you can bring the value in as an integer and then do the conversion in SQL.

I'm actually a little surprised because the 0 date on Excel is essentially Jan 0, 1900, which is Dec 31, 1899. I suspect there is an issue with the lack of leap year in 1900. Excel has the value of "60" represented as Feb 29,1900. This is amusing, I hadn't realized that Excel had this bug.

So, the above code works, for all values greater than 61.

这篇关于只需将mysql数据库中的5位数字转换为日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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