Problems changing date format of date as string

99封情书 提交于 2019-12-13 19:30:43

问题


I am currently trying to convert yyyymmdd type of date to a ddmmyyy format.

  • I've tried using DATE function and something like this:

    =DATE(LEFT(A3;4);MID(A3;5;3);RIGHT(A3;7))

    Original date for this function is 20120401 but the formula returns: 16.12.2104.

  • I've tried using functions YEAR, MONTH and DAY instead of LEFT, MID and RIGHT but that's not the right way.

  • I also tried using DATEVALUE but since Excel probably doesn't recognize yyyymmdd as a date, it gives me a #VALUE! error.

  • I've found a couple of solutions for SQL but it isn't my strong side yet - and this should be achievable easily in Excel.

Is there a way to do this in Excel?


回答1:


Applying =DATE(LEFT(A3;4);MID(A3;5;3);RIGHT(A3;7)) to 20120401 in A3 is effectively to reassemble the component characters as below on the left:

These effectively become converted as on the right.

The solution was simply to exclude the digits highlighted red with:
=DATE(LEFT(A3;4);MID(A3;5;2);RIGHT(A3;2)) but the locale might have been a factor and when dealing with date serial numbers and/or what appears to be a date but is a string various other issues might have been involved.




回答2:


Consider:

=DATE(LEFT(A1,4),MID(A1,5,2),RIGHT(A1,2))



来源:https://stackoverflow.com/questions/19407673/problems-changing-date-format-of-date-as-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!