日期/时间的字符串表示形式之间的差异
在 Excel 2007 中,我想要以下字符串日期/时间的差异:
A B C
1 Date1 Date2 Difference of A and B
2 2009.11.28 01:25:46:0287 2009.11.28 01:25:46:0287 ?
3 2009.11.28 01:25:46:0443 2009.11.28 01:25:46:0443 ?
我想要通过将字符串转换为日期/时间来获得差异,然后将结果作为两个转换后的日期/时间的差异。
In Excel 2007, I want the differences for the following string date/times:
A B C
1 Date1 Date2 Difference of A and B
2 2009.11.28 01:25:46:0287 2009.11.28 01:25:46:0287 ?
3 2009.11.28 01:25:46:0443 2009.11.28 01:25:46:0443 ?
I want the differences by converting strings to date/time and then the results as differences of two converted date/times.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
计算零的相当冗长的方法(对于示例):
根据特殊要求,并且稍微短一些:
A rather long-winded way to calculate zero (for the examples):
By special request and very slightly shorter:
我想不出一个真正好的方法来做到这一点......希望其他人能想到。话虽如此,以下内容可能会满足您的需求。
要转换主日期部分,请使用以下公式(假设字符串日期位于 A1 中):
要转换第二小数部分,请使用:
日期/时间部分可以轻松减去,第二小数部分也可以。
我遇到麻烦的地方是将这些部分重新组合成一个整体,Excel 实际上会以合理的方式显示。最后,我将两个日期之间的差值乘以 86400(= 24 * 60 * 60 - 典型一天中的秒数),然后将差值添加到小数第二部分中。
希望这有帮助。
问候,
理查德
·P.S.这个解决方案有很多我不喜欢的地方,其中最大的是公式的脆弱性 - 如果日期格式发生变化,公式将需要调整。
I couldn't come up with a really nice way of doing this... hopefully someone else will. Having said that, the following may give you what you need.
To convert the main date part, use the following formula (this assumes the string date is in A1):
To convert the fractional second part, use:
The date / time part can easily be subtracted, as can the fractional second part.
The place I ran into trouble was recombining those parts into a whole that Excel will actually display in a sensible way. I finally took the difference between the two dates and multiplied by 86400 (= 24 * 60 * 60 - number of seconds in a typical day) then added the difference in the fractional second part.
Hope this helps.
Regards,
Richard
P.S. There are quite a lot of things I don't like about this solution, the biggest of which is the fragility of the formulas - if the date format changes, the formulas will need to be adjusted.