Count Days in a Month

Vanda_a

Well-known Member
Joined
Oct 29, 2012
Messages
934
Dear all

Could someone explain below formula to me please.
Rich (BB code):
=DAY(DATE(YEAR(A1),MONTH(A1)+1,1)-1)
The red parts, no idea.

Thank you very much
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Dear all

Could someone explain below formula to me please.
Rich (BB code):
=DAY(DATE(YEAR(A1),MONTH(A1)+1,1)-1)
The red parts, no idea.

Thank you very much

1. Given a date, the formula constructs first a first day date following the month/year of A1.

A1 = 4/20/2015

==> 5/1/2015

Note that this is DATE applied to 2015, 5 (MONTH of A1, which is 4, plus 1) and 1.

2. Subtracting 1 from the first day date of (1), that is,

5/1/2015 minus 1, we get:

==> 4/30/2015

3) DAY applied to (2), we get:

==> 30

which is days April (of 2015) counts.
 
Upvote 0
1. Given a date, the formula constructs first a first day date following the month/year of A1.

A1 = 4/20/2015

==> 5/1/2015

Note that this is DATE applied to 2015, 5 (MONTH of A1, which is 4, plus 1) and 1.

2. Subtracting 1 from the first day date of (1), that is,

5/1/2015 minus 1, we get:

==> 4/30/2015

3) DAY applied to (2), we get:

==> 30

which is days April (of 2015) counts.

Understand it now. Thank you very much.
 
Upvote 0
Vanda_a, Good morning.

It's a very good explanation about this formula.
Aladin Akyurek, congratulations!

I suggest you to use this formula:

=DAY(EOMONTH(A1),0)

I think it's more simple.

I hope it helps.
Have a nice day.
 
Upvote 0
Alternative to last day of previous month from today:

=DAY(TODAY()-DAY(TODAY()))

or a date in A1

=DAY(A1-DAY(A1))
 
Upvote 0

Forum statistics

Threads
1,214,386
Messages
6,119,214
Members
448,874
Latest member
b1step2far

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top