fawad aslam
fawad aslam

Reputation: 23

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

Let say cell A1 has year
cell B1 has month

In cell C1 I want the number of days of month given in cell B1 in the year A1

For example: If A1=2016, B1=2, now C1 should return the number of days in February 2016.

What I have tried

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

But this does not work

I'd be grateful for a solution.

Upvotes: 2

Views: 5190

Answers (4)

barry houdini
barry houdini

Reputation: 46341

Less transparent but this will also work

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

format as general

Upvotes: 0

Subodh Tiwari sktneer
Subodh Tiwari sktneer

Reputation: 9976

Or you may try this...

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

Upvotes: 2

PedroMVM
PedroMVM

Reputation: 342

Excel have a lot of functions that are unknown for most users. EOMONTH is the function you need in your case. 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. In B1 you put:

=EOMONTH("A1",0)

So in B1 will show 30/04/2017 (for those whose date format is dd/mm/yyyy).

Upvotes: -1

Gary's Student
Gary's Student

Reputation: 96753

Consider:

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

enter image description here

Upvotes: 2

Related Questions