且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Excel日期/时间差

更新时间:2021-11-25 09:00:09

您不能使用YEAR函数获取年份差,因为这将在2012年12月31日至2013年1月1日之间给出1年,而只有一天的时间.....

You can't use YEAR function to get year difference because that will give 1 year between 31st December 2012 and 1st Jan 2013 when there is only one day.....

....同样,您可能会遇到MONTH和DAY的问题(例如MONTH总是返回1到12之间的数字,而在这种情况下,您只会期望0到11之间的数字)

....similarly you can have problems with MONTH and DAY (e.g. MONTH always returns a number between 1 and 12 whereas in this context you would only expect numbers between 0 and 11)

尝试用DATEDIF表示前3个,然后按贾斯汀的建议HOURMINUTESECOND

Try DATEDIF for the first 3 then HOUR, MINUTE, SECOND as Justin suggests

假设A2中的开始日期/时间和B2中的结束日期/时间分别尝试使用以下公式分别表示年,月,日,时,分和秒

Assuming start date/time in A2 and end date/time in B2 try these formulas respectively for Years, Months, Days, Hours, Minutes and Seconds

=DATEDIF(A2,B2-(MOD(A2,1)>MOD(B2,1)),"y")

=DATEDIF(A2,B2-(MOD(A2,1)>MOD(B2,1)),"ym")

=DATEDIF(A2,B2-(MOD(A2,1)>MOD(B2,1)),"md")

=HOUR(B2-A2)

=MINUTE(B2-A2)

=SECOND(B2-A2)

将所有单元格设置为常规格式

format all cells as general

由于月份/年份的长短不一,您可能会出现一些差异……

You may get some discrepancies because of variable month/year lengths......