以格式转换文本日期

时间:2017-06-28 03:46:25

标签: excel date text format

我的文字格式化日期如下:

June 12th 2017, 9:07am PDT

如何以日期格式转换它(经典方法Format Cells和DateValue()不起作用)?

谢谢。

1 个答案:

答案 0 :(得分:1)

我的解决方案使用一个帮助表来列出所有12个月及其序列号A1:B12

January     1
February    2
March       3
April       4
May         5
June        6
July        7
August      8
September   9
October    10
November   11
December   12

假设值在D10

获取单独的元素

月:

=VLOOKUP(LEFT(D10,FIND(" ",D10)-1),A1:B12,2,FALSE)

日期:

=IFERROR(VALUE(RIGHT(LEFT(D10,FIND(" ",D10)+2),2)),RIGHT(LEFT(D10,FIND(" ",D10)+1),1))

年:

=RIGHT(LEFT(D10,FIND(",",D10)-1),4)

小时

=IF(RIGHT(LEFT(D10,FIND(":",D10)+4),2)="am",RIGHT(LEFT(D10,FIND(":",D10)-1),2),RIGHT(LEFT(D10,FIND(":",D10)-1),2)+12)

分:

=RIGHT(LEFT(D10,FIND(":",D10)+2),2)

所有这一切都在DATETIME函数中合并为一个公式:

=DATE(RIGHT(LEFT(D10,FIND(",",D10)-1),4),VLOOKUP(LEFT(D10,FIND(" ",D10)-1),A1:B12,2,FALSE),IFERROR(VALUE(RIGHT(LEFT(D10,FIND(" ",D10)+2),2)),RIGHT(LEFT(D10,FIND(" ",D10)+1),1)))+TIME(IF(RIGHT(LEFT(D10,FIND(":",D10)+4),2)="am",RIGHT(LEFT(D10,FIND(":",D10)-1),2),RIGHT(LEFT(D10,FIND(":",D10)-1),2)+12),RIGHT(LEFT(D10,FIND(":",D10)+2),2),0)

然后将单元格的格式更改为:

mmmm dd yyyy hh:mm AM/PM "PDT"

这将给出:

June 12 2017 09:07 AM PDT

enter image description here

要添加逗号(,),请使用自定义格式:

mmmm dd yyyy"," hh:mm AM/PM "PDT"