简体   繁体   English

如何计算 Excel 中的天数

[英]How to calculate number of days in Excel

I have a date format like 2020-01-17.I would like to calculate number of days till today date.我有一个像 2020-01-17 这样的日期格式。我想计算到今天为止的天数。 I'm trying it's like我正在尝试它就像

    =today() - B2

However it's not working.但是它不起作用。

Edit编辑

I changed the format to 01/17/2020 and did我将格式更改为 01/17/2020 并做了

 =today() - B2 

The result comes as 3/23/1900.结果是 1900 年 3 月 23 日。

This is wrong and I would like to see in number of days.这是错误的,我想在几天内看到。

very simple Check Out Image enter image description here非常简单 查看图片在此处输入图片描述

I think there are 2 issues that you're seeing here.我认为您在这里看到了两个问题。

The result comes as 3/23/1900.结果是 1900 年 3 月 23 日。

  1. The reason you're seeing this result as 3/23/1900 is probably because of the format of the cell.您看到此结果为3/23/1900的原因可能是因为单元格的格式。 Change cell format to number and you should see your result as a number.将单元格格式更改为数字,您应该会看到结果为数字。
    1. Or you can also use the formula with a VALUE formula like so =VALUE(today() - B2)或者您也可以将公式与 VALUE 公式一起使用,例如=VALUE(today() - B2)

I would like to calculate number of days till today date我想计算到今天为止的天数

  1. You can always use a simple subtraction of the two dates.您始终可以使用两个日期的简单减法。 You can also use the DATEDIF function and extract the difference between dates in Years, Months, Days and more.您还可以使用 DATEDIF function 并提取年、月、日等日期之间的差异。 Example: =DATEDIF(today(), B2,"D")示例: =DATEDIF(today(), B2,"D")

Here is the documentation for this DATEDIF function. 这是此 DATEDIF function 的文档

Note : Below is the warning from Microsoft注意:以下是来自微软的警告

Warning : Excel provides the DATEDIF function in order to support older workbooks from Lotus 1-2-3.警告:Excel 提供了 DATEDIF function 以支持来自 Lotus 1-2-3 的旧工作簿。 The DATEDIF function may calculate incorrect results under certain scenarios. DATEDIF function 在某些情况下可能会计算出错误的结果。 Please see the known issues section of this article for further details有关详细信息,请参阅本文的已知问题部分

You can you use the datedif fx link: https://exceljet.net/excel-functions/excel-datedif-function您可以使用 datedif fx 链接: https://exceljet.net/excel-functions/excel-datedif-function

=DATEDIF(B2,TODAY(),"D") =DATEDIF(B2,今天(),"D")

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM