简体   繁体   English

如何在单个公式中在 Excel 中返​​回当月的本月至今日?

[英]How to return the Month-to-Date day of current month in Excel within a single formula?

I did the following in excel to get the MTD day of current month - ie if today is 31 march 2020, I should get 30 as number of days in the MTD.我在 excel 中执行了以下操作以获得当月的 MTD 日 - 即如果今天是 2020 年 3 月 31 日,我应该在 MTD 中获得 30 作为天数。

Im wondering whether this can be done in a single formula within the need of having =today() formula to get the current date first and separately use =day()-1 to get the MTD days?我想知道这是否可以在需要 =today() 公式首先获取当前日期并单独使用 =day()-1 来获取 MTD 天数的情况下在单个公式中完成? - this case would be 2 separate formulas. - 这种情况将是 2 个单独的公式。

在此处输入图片说明

在 Google 表格中尝试这样:

=EOMONTH(TODAY(), 0)

To get the date 1 day before the current date, ie the MTD days that have completed you could use this:要获得当前日期前 1 天的日期,即已完成的 MTD 天数,您可以使用:

=DATE(YEAR(TODAY()),MONTH(TODAY()),DAY(TODAY())-1)

However, what is the MTD on April 1, 2020?但是,2020 年 4 月 1 日的 MTD 是多少? It'd be april fools I guess becuase their is no April 0, 2020. To get around this you could use:我猜这是愚人节,因为他们不是 2020 年 4 月 0 日。要解决这个问题,您可以使用:

=DATE(YEAR(TODAY()),MONTH(TODAY()),IF(DAY(TODAY())-1>0,DAY(TODAY())-1,DAY(TODAY())))

Admittedly the second one is pretty messy.不可否认,第二个是相当混乱的。

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

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