mysql 日期变成5位数字,只需将mysql数据库中的5位数字转换为日期

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 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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值