让 Excel 为您计算! ...使用 TEXT 函数。
DATEDIF 函数(类似于 VBA 的 DateDiff 函数)是一种快速计算整年、月、日、小时等的方法。
理想的做法是将该值存储为“天数”(应尽可能执行此操作,因为 Excel 以相同的方式存储日期。
TEXT 工作表函数(或 VBA 中的 FORMAT 函数)可用于格式化持续时间和时间跨度,就像格式化日期和时间一样。
例如:
如果单元格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( Date1, Date2, 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