简体   繁体   English

获取给定月份和年份EXCEL中一个月的天数

[英]Get number of days for a month from given month and year EXCEL

Let say cell A1 has year 假设单元格A1具有年份
cell B1 has month 单元格B1有一个月

In cell C1 I want the number of days of month given in cell B1 in the year A1 在单元格C1我希望在年份A1在单元格B1中给出的月份的天数

For example: If A1=2016 , B1=2 , now C1 should return the number of days in February 2016. 例如:如果A1=2016B1=2 ,那么C1应该返回2016年2月的天数。

What I have tried 我尝试过的

In C1 C1
=DAY(DATE(YEAR(A1),MONTH(B1)+1,))

But this does not work 但这行不通

I'd be grateful for a solution. 我将不胜感激。

Consider: 考虑:

=DATE(A1,B1+1,1)-DATE(A1,B1,1)

在此处输入图片说明

Or you may try this... 或者你可以试试这个...

=DAY(EOMONTH(DATE(A1,B1,1),0)) = DAY(EOMONTH(DATE(A1,B1,1),0))

Less transparent but this will also work 透明度较低,但这也会起作用

=42-DAY(DATE(A1,B1,42))

format as general 一般格式

Excel have a lot of functions that are unknown for most users. Excel具有许多大多数用户都不知道的功能。 EOMONTH is the function you need in your case. EOMONTH是您所需要的功能。 It returns the last date of the month for a given date. 它返回给定日期的月份的最后日期。 Consider you have a cell A1 with TODAY function and you want the last date of the month. 假设您有一个具有TODAY功能的单元格A1 ,并且想要该月的最后日期。 In B1 you put: 在B1中,您输入:

=EOMONTH("A1",0)

So in B1 will show 30/04/2017 (for those whose date format is dd/mm/yyyy ). 因此,在B1中将显示30/04/2017 (对于那些日期格式为dd/mm/yyyy的日期)。

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

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