How to a convert a string in this format “20180101

2019-01-20 20:15发布

This question already has an answer here:

What formula can I use to transform the string into a date value that will appear as 01/01/2018?

4条回答
成全新的幸福
2楼-- · 2019-01-20 20:36

Use the DATEVALUE() function which takes as input a text format. Not that if your output cell is not in Date format you will see a simple int insteade of the expected 1/1/2016.

I refer you to the DATEVALUE function documentation for more insight on the input format and so on

查看更多
相关推荐>>
3楼-- · 2019-01-20 20:39

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

OR

=REPLACE(REPLACE(A1,7,0,"-"),5,0,"-")+0

OR

=DATEVALUE(REPLACE(REPLACE(A1,7,0,"-"),5,0,"-"))

(Where A1 is the date to convert)

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.

查看更多
劳资没心,怎么记你
4楼-- · 2019-01-20 20:39

use the code below

=RIGHT((text),2)&"/"&MID((text),5,2)&"/"&LEFT((text),4)
查看更多
Rolldiameter
5楼-- · 2019-01-20 20:44

Use Data, TextToColumns, Fixed width, Date: YMD, Finish. Possibly Date: YDM depending on your string date format (you provided an ambiguous example).

enter image description here

查看更多
登录 后发表回答