如何从 google 文档或 excel 中的日期时间字符串中删除序数?

How to remove ordinals from datetime strings in google docs or excel?

我有一个日期时间列表,其中恰好有序号(第 1、第 2、第 3)。这会导致处理日期和转换为 unix 时间时出现问题。

如何从日期中删除 'rd' 或 'th' 后缀?

示例日期:

April 23rd
Apr 24th
Apr 30th
May 1st
May 7th
May 8th
May 15th
May 21st
May 22nd
May 28th
Jun 18th
Jun 19th
Jun 26th

如果日期只是文本并且总是有最后两个字母,那么它就是

=LEFT(A1,LEN(A1)-2)

如果你想先检查字母是否存在,你可以使用类似

的东西
=IF(OR(RIGHT(A1,2)={"st","nd","rd","th"}),LEFT(A1,LEN(A1)-2),A1)

必须在 Google 工作表

中作为数组公式输入
=ArrayFormula(=IF(OR(RIGHT(A1,2)={"st","nd","rd","th"}),LEFT(A1,LEN(A1)-2),A1))

试试这个:

=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"st",""),"nd",""),"rd",""),"th","")

然后,将其转换为具有今天年份的 "real" 日期:

=--SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"st",""),"nd",""),"rd",""),"th","")

或者更短(在 Excel 中工作,不确定 Google):

=LOOKUP(1E+307,--SUBSTITUTE(A1,{"st","nd","rd","th"},""))

务必将其格式化为日期