简体   繁体   English

Excel中的日期转换公式

[英]date conversion formula in excel

I have some dated in this format "09-MAY-13 06.42.46.097127000 PM" and need to convert to this format "2013-05-09T18:42:47.132Z". 我有一些日期格式为“ 09-MAY-13 06.42.46.097127000 PM”,并且需要转换为此格式“ 2013-05-09T18:42:47.132Z”。 my goal is to find out which happend earlier. 我的目标是找出较早发生的情况。 I am not sure how to format these dates. 我不确定如何格式化这些日期。

2013-05-09T18:42:47.132Z    09-MAY-13 06.42.46.097127000 PM
2013-05-08T20:56:55.821Z    06-MAY-13 03.22.09.129443000 PM
2013-05-08T20:51:45.287Z    06-MAY-13 03.03.22.975700000 PM
2013-05-08T20:55:34.719Z    06-MAY-13 10.40.55.924181000 PM

How I can do that?? 我该怎么做?

I originally posted an answer which converted one of your formats to the other. 我最初发布的答案将您的一种格式转换为另一种格式。 I now see that you need to compare them, so you can convert this format in A2 to date/number values .... 现在,我需要compare它们,因此可以将A2中的这种格式转换为日期/数字值...。

09-MAY-13 06.42.46.097127000 PM 2013年5月9日06.42.46.097127000 PM

.....with this formula .....用这个公式

=SUBSTITUTE(SUBSTITUTE(A2,".",":",1),".",":",1)+0

and this format in A3 而这种格式在A3中

2013-05-09T18:42:46.097z 2013-05-09T18:42:46.0​​97z

....with this formula ....用这个公式

=SUBSTITUTE(SUBSTITUTE(A3,"T"," "),"z","")+0

You can format the results how you like, leave as numbers or format as m/d/yyyy hh:mm:ss.000 or similar. 您可以随意设置结果格式,保留为数字或格式为m/d/yyyy hh:mm:ss.000或类似格式。 you can now compare easily with a formula like 您现在可以轻松地将公式与

=B2>B3

or get the smaller or larger with MIN or MAX 或以MIN或MAX变小或变大

If have a value of your original style in cell A1, place the following formula in a different cell: 如果在单元格A1中具有原始样式的值,则将以下公式放在另一个单元格中:

=DATE((2000+MID(A1,8,2)),MATCH(MID(A1,4,3),{"JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"},0),LEFT(A1,2))+TIME(MID(A1,11,2)+IF(RIGHT(A1,2)="PM",12,0),MID(A1,14,2),MID(A1,17,12))

Then, in that target cell, apply the following format: 然后,在该目标单元格中​​,应用以下格式:

yyyy-mm-ddThh:mm:ssZ

Please note the following: 请注意以下事项:

  • This assumes that all of your months are 3 characters (JAN, FEB, MAR). 假设您所有月份均为3个字符(JAN,FEB,MAR)。 Since your example was "MAY" (already 3 characters), I don't know with certainty how your other months appear. 由于您的示例是“ MAY”(已经有3个字符),因此我不确定您其他月份的表现如何。 Longer month names complicate the formula a bit. 较长的月份名称会使该公式稍微复杂化。 I can help with this if you need it and don't know how to do it. 如果您需要它并且不知道如何做,我可以为您提供帮助。
  • I couldn't find a way to force Excel to display fractional seconds in the context of such complex date/time formatting, even though your example showed seconds subdivided to the thousandths. 即使您的示例显示秒细分为千分之一,我也无法找到一种方法来强制Excel在如此复杂的日期/时间格式的情况下显示小数秒。 Hopefully this isn't a deal-breaker. 希望这不是一个破坏交易的行为。 If it's necessary to display fractional seconds, you may need to handle this with a separate formula to display the result as text, independent of the formula above, which you can use for your calculations of which date came earlier. 如果需要显示小数秒,则可能需要使用单独的公式来处理此问题,以将结果显示为文本,而与上面的公式无关,您可以将其用于计算较早的日期。

To add to Joe's answer... To get Excel to compare one column to the other you need to do the same sort of manipulation from the first column as the second. 要添加到Joe的答案中……要使Excel将一个列与另一个列进行比较,您需要从第一列开始进行与第二列相同的操作。

That would look like 看起来像

=DATE(LEFT(A1,4),MID(A1,6,2),MID(A1,9,2))+TIME(MID(A1,12,2),MID(A1,15,2),MID(A1,18,5))

Once you have a new column for each of these transformations it should be simple to have Excel compare them. 一旦对每个转换都有一个新列,使Excel比较它们应该很简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM