This might be a re-post, but I haven't been able to find anything that answers the question for me. I have a table with days listed as doubles like 435.6 or 5.2 and I need to convert this into a month. I've tried:
这可能是一个重新发布的帖子,但我找不到任何可以回答这个问题的内容。我有一张桌子,天数列为双打,如435.6或5.2,我需要将其转换为一个月。我试过了:
SELECT day FROM table WHERE DATE_ADD('2014-01-01', INTERVAL 31 DAY);
But that query just spits out the same. Any help please.
但是那个查询只是吐出一样的。请帮忙。
1 个解决方案
#1
0
edited version: Assuming your table is named t
and your decimal column is named d
编辑版本:假设您的表名为t,并且您的十进制列名为d
select date_format(date_add('2014-01-01', interval d day),"%m") from t;
This should add your epoch date ('2014-01-01'
) and format the result as a number (00-12), after adding d
days to the epoch. For the month represented as a word (January-December), use "%M"
. here's documentation for DATE_FORMAT
.
这应该添加您的纪元日期('2014-01-01'),并在将d天添加到纪元后将结果格式化为数字(00-12)。对于以单词(1月至12月)表示的月份,请使用“%M”。这里是DATE_FORMAT的文档。
here is a fiddle of the above code working for sample values
这里是上面代码的小提琴,用于样本值
#1
0
edited version: Assuming your table is named t
and your decimal column is named d
编辑版本:假设您的表名为t,并且您的十进制列名为d
select date_format(date_add('2014-01-01', interval d day),"%m") from t;
This should add your epoch date ('2014-01-01'
) and format the result as a number (00-12), after adding d
days to the epoch. For the month represented as a word (January-December), use "%M"
. here's documentation for DATE_FORMAT
.
这应该添加您的纪元日期('2014-01-01'),并在将d天添加到纪元后将结果格式化为数字(00-12)。对于以单词(1月至12月)表示的月份,请使用“%M”。这里是DATE_FORMAT的文档。
here is a fiddle of the above code working for sample values
这里是上面代码的小提琴,用于样本值