如何转换这种格式的字符串“20180101"?到 Excel 中的日期值,例如 01/01/2018? [英] How to a convert a string in this format "20180101" into a date value like 01/01/2018 in Excel?
问题描述
我可以使用什么公式将字符串转换为显示为 01/01/2018 的日期值?
What formula can I use to transform the string into a date value that will appear as 01/01/2018?
推荐答案
如果您正尝试从一个公式到另一个单元格中执行此操作,而不是在原位执行此操作(为此,请使用文本到列",根据 Jeeped 的回答),您可以组合 DATE
和 MID
,或使用 REPLACE
并用 +0进行转换code> 或
DATEVALUE
:
If you are trying to do this from a formula into another cell, and not in situ (For which, use "Text to Columns" as per Jeeped's answer), you can either combine DATE
and MID
, or use REPLACE
and convert with +0
or DATEVALUE
:
=DATE(MID(A1,1,4), MID(A1,5,2), MID(A1,7,2))
或
=REPLACE(REPLACE(A1,7,0,"-"),5,0,"-")+0
或
=DATEVALUE(REPLACE(REPLACE(A1,7,0,"-"),5,0,"-"))
(其中A1
是要转换的日期)
(Where A1
is the date to convert)
第一个公式只是将数字切成2018
01
01
并将它们用作年、月和日.第二个 2 首先在位置 7 ("201801-01"
) 插入(即 REPLACE
0 个字符)一个连字符,然后在位置 5 ("2018-01-01"
) 并将字符串转换回数字/日期.
The first formula just cuts the number up into 2018
01
01
and uses those as Year, Month and Day. The second 2 work by first Inserting (i.e. REPLACE
0 characters) a hyphen at position 7 ("201801-01"
) and then at position 5 ("2018-01-01"
) and converting the string back to a number/date.
这篇关于如何转换这种格式的字符串“20180101"?到 Excel 中的日期值,例如 01/01/2018?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!