如何比较Excel中文本字符串中的两个日期?

发布于 2025-02-09 04:26:05 字数 428 浏览 3 评论 0原文

我有一组具有这种格式的数据: 每个单元格都有一个或一些名称,每个单元格之后都有一个日期。我想比较每个单元格中显示的日期,并检查它们是否相同。

单元内容的示例:大学XXX(2016-10-21)公司YYY(2016-10-22)

“

我使用了公式:= mid = mid(a1,search(“(”) +1,10)要找到第一个约会。我怎么能找到第二名,第三名,...日期?

“,a1,1 )

I have a set of data with this format:
Each cell has one or some names, each of them are followed by a date. I want to compare the dates which are presented in each cell and check whether they are the same or not.

Example of a cell content: university XXX (2016-10-21) company YYY (2016-10-22)

example

I used the formula: =MID(A1,SEARCH("(",A1,1)+1,10) to find the first date. how could I find 2nd, 3rd, ... dates?

Thank you in advance,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

囍笑 2025-02-16 04:26:05

最简单的话,如果逐步完成:
因此,分解您的MID(A1,搜索(“(”,A1,1)+1,10)(并使其更特定于日期 - 您不想匹配“(kacst)”)为:
B1:= search(“(2”,A1,1)和H1:= MID(A1,B1+1,10)
然后添加
C1:= search(“(2”,A1,B1+1)这告诉搜索是在其已经找到的字符之后从字符开始的
I1:= MID(A1,C1+1,10)
ETC

Easiest if done step by step:
So break down your MID(A1,SEARCH("(",A1,1)+1,10) (and make it more specific to dates - you don't want to match "(KACST)") as:
B1: =SEARCH("(2",A1,1) and H1: =mid(A1,B1+1,10)
Then add
C1: =SEARCH("(2",A1,B1+1) This tells the search to start from the character after the one it has already found
I1: =mid(A1,C1+1,10)
etc

月下凄凉 2025-02-16 04:26:05

如果您有Office 365(Windows),这是应有的一种方法,具体取决于实际数据的可变性:

=LET(arr,--MID(FILTERXML("<t><s>" & SUBSTITUTE(A1," ","</s><s>") & "</s></t>","//s[contains(.,'(')]"),2,10),
         numDates,COUNT(arr),
         AGGREGATE(14,6,arr,SEQUENCE(numDates)))
  • 创建XML
  • 使用filterxml仅返回包含的节点(
  • 将这些节点转换为日期序列号
    • will =&gt;错误,如果后的10个字符(不是数字
  • 返回这些值。
  • 那么您可以比较这些值,但是想要

“在此处输入映像说明”

例如,如果您想查看是否全部查看是否全部日期是相同的:

=COUNT(UNIQUE(
      LET(arr,--MID(FILTERXML("<t><s>" & SUBSTITUTE(A1," ","</s><s>") & "</s></t>","//s[contains(.,'(')]"),2,10),
         numDates,COUNT(arr),
         AGGREGATE(14,6,arr,SEQUENCE(numDates)))))=1

如果您没有Office 365,或者您的数据比您显示的内容更多样化,因此我用于确定括号的值是否可靠的方法,我建议您开发一个VBA解决方案,可能使用正则表达式。

If you have Office 365 (Windows), here's one way that should work, depending on the variability in your real data:

=LET(arr,--MID(FILTERXML("<t><s>" & SUBSTITUTE(A1," ","</s><s>") & "</s></t>","//s[contains(.,'(')]"),2,10),
         numDates,COUNT(arr),
         AGGREGATE(14,6,arr,SEQUENCE(numDates)))
  • create an XML
  • Use FILTERXML to return only nodes containing the (
  • Convert those nodes to a date serial number
    • Will => error if the 10 characters subsequent to the ( are not numeric
  • Return those values.
  • Then you can compare those values however you want

enter image description here

For example, if you wanted to see if all the dates were the same:

=COUNT(UNIQUE(
      LET(arr,--MID(FILTERXML("<t><s>" & SUBSTITUTE(A1," ","</s><s>") & "</s></t>","//s[contains(.,'(')]"),2,10),
         numDates,COUNT(arr),
         AGGREGATE(14,6,arr,SEQUENCE(numDates)))))=1

If you don't have Office 365, or if your data is more varied than what you show, such that the method I used for determining if the parenthesized values are dates is not reliable, I suggest you develop a VBA solution, possibly using Regular Expressions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文