让 Excel 为您计算!...使用该TEXT
功能。
该DATEDIF
函数(类似于 VBA 的DateDiff
函数)是一种快速计算整年、月、日、小时等的方法。
理想情况下,您将值存储为“天数”(应尽可能执行此操作,因为 Excel 以相同的方式存储日期。
工作表TEXT
函数(或FORMAT
VBA 中的函数)可用于格式化持续时间和时间跨度,就像格式化日期和时间一样。
例如:
如果单元格A1
包含您想要格式的值,例如12345
,(12,345 天),您可以使用:
=TEXT(A1,"y \yr, M \m, d \d")
...这将返回:
33 yr, 10 m, 18 d
指定日期/时间值的位置Y,M,D,H,M,S
以及更多。您可以在数字之间指定您想要的任何内容;如果您想要的字母是上面列出的字母之一,您可以在\
前面放置一个强制显示字母(d
如上例中的。
如果您的值A1
包括部分日期,例如12345.6789
,您可以将其转换为:
=TEXT(A1,"y \yr, M \m, d \d, h \hr, m \m, s \s")
....返回:
33 yr, 10 m, 18 d, 16 hr, 17 m, 37 s
未记录的工作表功能:DATEDIF
有一个未记录的工作表函数称为DATEDIF
(类似于 VBA 的DATEDIFF
函数),它可以快速计算年、月、日、小时等之间的差异......
“ DATEDIF被视为公式家族的醉表弟。Excel 知道它过着幸福而有用的生活,但不会在礼貌的谈话中谈论它。” — 奇普·皮尔逊
用法:
DATEDIF的语法如下:
=DATEDIF(
<em> Date1,
<em> Date2,
<em> Interval
<代码>)
其中:
-Date1
是第一次约会。
-Date2
是第二次约会。
-Interval
是要返回的区间类型。
Code Meaning Complete 'calendar' days/months/years
---- ------------------------------- --------------------------------------------------------------
m Months Months between the dates
d Days Days between the dates
y Years Years between the dates
ym Months Excluding Years Months between the dates as if they were of the same year
yd Days Excluding Years Days between the dates as if they were of the same year
md Days Excluding Years & Months Days between the dates as if they were of the same month & year