Excel: 将文本格式化为可识别的日期

huangapple go评论50阅读模式
英文:

Excel: Formatting text into a recognisable date

问题

我有一个包含许多行的.csv文件,其中日期的格式如您在A列中所见。我手动复制了日期,然后在B列中将其更改为我想要的格式,同时Excel也将其识别为日期(而不是文本)。

我的问题是,有没有人知道如何通过一些公式魔法或其他方法让Excel自动以这种方式格式化日期?

谢谢!

英文:

I have a .csv file with many rows where the date is formatted as you see in column A. I manually copied and then changed the date to how I want it to be in column B where it's also recognised by Excel as a date (and not text).

My question is does anyone know how I can get Excel to format the date like this automatically via some forumula magic or some other method?

Thanks

Excel: 将文本格式化为可识别的日期

答案1

得分: 4

这是公式的翻译部分:

  • 第一个公式是针对Office 365的,它会返回正确的日期。这里会去掉逗号并重新排列顺序。--将其转换为数字。

  • 如果月份缩写与本地设置不匹配,它将无法正常工作。

  • 对于较旧的版本,使用下面的公式:

    =--(TRIM(MID(SUBSTITUTE(SUBSTITUTE(A1,""", ""), " ", REPT(" ", 999)), 999, 999)) & " " &
    TRIM(MID(SUBSTITUTE(SUBSTITUTE(A1, """, ""), " ", REPT(" ", 999)), 1, 999)) & " " &
    TRIM(MID(SUBSTITUTE(SUBSTITUTE(A1, """, ""), " ", REPT(" ", 999)), 1998, 999)) & " " &
    TRIM(MID(SUBSTITUTE(SUBSTITUTE(A1, """, ""), " ", REPT(" ", 999)), 3996, 999)))
    

希望这有所帮助。

英文:

Another formula that should return the correct date. This does require Office 365:

=--TEXTJOIN(" ",,INDEX(TEXTSPLIT(SUBSTITUTE(TRIM(A1),",","")," "),,{2,1,3,5}))

This removes the , and then rearranges the order. The -- turns it into a number.

If the month abbreviations do not match the local settings it will not work

Excel: 将文本格式化为可识别的日期


For older versions:

=--(TRIM(MID(SUBSTITUTE(SUBSTITUTE(A1,",","")," ",REPT(" ",999)),999,999)) & " " &
TRIM(MID(SUBSTITUTE(SUBSTITUTE(A1,",","")," ",REPT(" ",999)),1,999)) & " " &
TRIM(MID(SUBSTITUTE(SUBSTITUTE(A1,",","")," ",REPT(" ",999)),1998,999)) & " " &
TRIM(MID(SUBSTITUTE(SUBSTITUTE(A1,",","")," ",REPT(" ",999)),3996,999)))

Excel: 将文本格式化为可识别的日期

答案2

得分: 0

=--SUBSTITUTE(REPLACE(A2,1,8,MID(A2,5,2)&"/"&LEFT(A2,3)&"/"), " @ ", " ")

英文:

Shorter formula for older versions:

=--SUBSTITUTE(REPLACE(A2,1,8,MID(A2,5,2)&"/"&LEFT(A2,3)&"/")," @ "," ")

(English-locale)

=--SUBSTITUTE(REPLACE(A2,1,8,MID(A2,5,2)&"/"&FIND(LEFT(A2,3),"  JanFebMarAprMayJunJulAugSepOctNovDec")/3&"/")," @ "," ")

(non-English locale)

huangapple
  • 本文由 发表于 2023年3月4日 03:12:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/75631022.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定