跳到主要内容

如何计算两个日期之间的天数,周数,月数或年数?

您是否考虑过在Excel中两个给定日期之间计算多少天,几周,几月或几年? 本教程可以帮助您尽快完成以下操作。


用公式计算两个日期之间的天数

要计算两个给定日期之间的天数,请使用以下公式:

1。 在要获取结果的空白单元格中输入以下任一公式:

=DATEDIF(A2,B2,"D")
=B2-A2

备注:在以上公式中, A2 是开始日期单元格, B2 是结束日期单元格。

2。 然后,将填充手柄向下拖动到要应用此公式的单元格上,并且已经计算了天数,请参见屏幕截图:


用公式计算两个日期之间的星期数

要计算两个日期之间的周数,您可以使用下面的便捷公式,只需从结束日期中减去开始日期并除以7。

1。 在空白单元格中输入以下任一公式:

=(DATEDIF(A2,B2,"D")/7)
=(B2-A2)/7

备注:在以上公式中, A2 是开始日期单元格, B2 是结束日期单元格。

2。 然后,向下拖动填充手柄以填充此公式,您将获得以十进制数字表示的星期,请参见屏幕截图:

  • Tips如果要获取两个日期之间的整周数,请应用以下公式:
  • = ROUNDDOWN((DATEDIF(A2,B2,“ d”)/ 7),0)
    = INT((B2-A2)/ 7)


计算天,周,月,年等两个日期之间的各种差异。

要记住的公式太多 Kutools for Excel's 日期和时间助手 功能,您可以根据需要快速获得两个日期之间的各种差异结果,而无需记住任何公式,例如周+天,月+周等。 点击下载Kutools for Excel!

Kutools for Excel:具有300多个方便的Excel加载项,可以在30天内免费试用,没有任何限制。 立即下载并免费试用!


用公式计算两个日期之间的月数

如果要确定两个日期之间的月数,可以使用此DATEDIF函数。

1。 请在要输出结果的空白单元格中输入以下公式:

=DATEDIF(A2,B2,"m")

备注:在以上公式中, A2 是开始日期单元格, B2 是结束日期单元格。

2。 然后,向下拖动填充手柄以填充此公式,您将获得给定两个日期之间的完成月份数,请参见屏幕截图:

  • Tips如果要获取两个日期之间的整周数,请应用以下公式:
  • = DATEDIF(A2,B2,“ m”)&“ months”&DATEDIF(A2,B2,“ md”)&“ days”


用公式计算两个日期之间的年数

使用上面的DATEDIF函数,您还可以计算两个日期之间的年数。

1。 将以下公式应用于空白单元格:

=DATEDIF(A2,B2,"y")

备注:在以上公式中, A2 是开始日期单元格, B2 是结束日期单元格。

2。 然后,将填充手柄向下拖动到要应用此公式的单元格上,所有年数都已如下图所示进行了计算:


用公式计算两个日期之间的年月日数

有时,您需要确切地知道两个日期之间有多少年,几个月和几天,在这种情况下,以下长公式可能会对您有所帮助。

1。 在空白单元格中,输入或复制以下公式:

=DATEDIF(A2, B2, "y") &" years "&DATEDIF(A2, B2, "ym") &" months " &DATEDIF(A2, B2, "md") &" days"

备注:在以上公式中, A2 是开始日期单元格, B2 是结束日期单元格。

2。 然后,拖动填充手柄以填充此公式,并立即计算日期之间的特定年,月和日数,请参见屏幕截图:


强大功能可计算几天,几周,几个月,几年中两个日期之间的各种差异

如果您有,可能是您对上述公式感到恼火 Kutools for Excel,其 日期和时间助手 功能,您可以根据需要快速获取两个日期之间的各种差异结果,例如周+天,月+周等。

请注意:申请这个 日期和时间助手,首先,您应该下载 Kutools for Excel,然后快速轻松地应用该功能。

安装后 Kutools for Excel,请这样做:

1。 单击要在其中查找结果的单元格,然后单击 库工具公式助手 > 日期和时间助手,请参见屏幕截图:

2。 在 日期和时间助手 对话框中,进行以下操作:

  • 单向阀 区别 选项从 Type 部分;
  • 参数输入 在文本框中,选择分别包含开始日期和结束日期的单元格;
  • 然后,根据需要选择输出结果类型。 例如,如果要获取两个日期之间的年,月,周和天数,则只需选择 年+月+周+天.

3。 完成设置后,请点击 OK 按钮,您将获得第一个计算结果,然后,只需将填充手柄向下拖动到要应用此公式的单元格,您将根据需要获得以下结果:

点击下载Kutools for Excel并立即免费试用!


更多有关日期和时间的文章:

  • 在Excel中计算午夜后的时间之间的小时数
  • 假设您有一个时间表来记录您的工作时间,则A列中的时间是今天的开始时间,B列中的时间是第二天的结束时间。 通常,如果您直接减去“ = B2-A2”来计算两次之间的时间差,则不会显示正确的结果,如左图所示。 如何在Excel中正确计算午夜后两次之间的小时数?
  • 计算两个日期之间的天数/工作日/周末数
  • 您是否曾经需要计算过Excel中两个日期之间的天数? 有时,您可能只想计算两个日期之间的工作日,有时,您只需要计算两个日期之间的周末天。 在特定条件下,您如何计算两个日期之间的天数?

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 Office 带来选项卡式界面,让您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
Comments (45)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Dateif formula how to input?
This comment was minimized by the moderator on the site
Hi I am trying to build up a salary report where i need to split a person salary by month if they completed that full month , and if their start or end date is after the beginning or the did of the month then calculate that month based on the network days worked. the problem I am getting when using the theses date formulas is that are not showing the correct completed month only. for example.

Start Date End Date
07/09/2022 11/01/2023

this should be 3 months and 26 days (18 working days in September and 8 working days in Jan 2023) = DatedIf formula is showing 4
Can anyone help?


thanks,
Charlotte
This comment was minimized by the moderator on the site
Quisiera saber, si podría calcular cuántos martes hay entre dos fechas; por ejemplo, en tres años o no es posible
Gracias de antemano por su colaboración
This comment was minimized by the moderator on the site
Hello, Pilar,
To get the number of a specific weekday, you can apply the below formula:
=SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(A2&":"&B2)))=3))


Note: A2 is the start date, B2 is the end date, and the number 3 indicates Tuesday, 1 to 7 indicates from Sunday to Saturday, you can change the number to your need.

Please try, hope it can help you!
This comment was minimized by the moderator on the site
Muchísimas gracias por su ayuda
This comment was minimized by the moderator on the site
Love Kutools! I purchased years ago and still visit the extednoffice.com site when I need fast solutions!
This comment was minimized by the moderator on the site
Avenger vs Marvell
perhitungan permainan roulette
perhitungan permainan sicbo
This comment was minimized by the moderator on the site
How can obtain age from two DOB. Eg- i need to calculate the age from DATE of Birth till the Date of Treatment was started
This comment was minimized by the moderator on the site
how to obtain matching no of months between two sets of dates ?
This comment was minimized by the moderator on the site
What is the formula for 01/05/2017 13:01:20 minus 01/05/2017 08:59:27 to get the total hours.
This comment was minimized by the moderator on the site
I need the following and cannot figure out the formula I have been given the date of birth, date of exam. I need a third date, (record purge date) that has the following rules; IF they are 18 or over by exam date, the purge date will be 7 years from exam date IF they are under 18 by exam date, the purge date would be 7 years from when they turn 18
This comment was minimized by the moderator on the site
Thank You so much for your way. 2017 calendar printable
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations