Google-sheets – way to generate number of days in a month

formulasgoogle sheets

The title kind of says it all but just to give you the use case, I have a spreadsheet where I track monthly advertisement revenue and want to end up with a daily revenue column.

Here's a simplified example of what I have today:

MONTH   | TOTAL REVENUE
-----------------------
2012-04 | $456.78
2012-03 | $345.67
2012-02 | $234.56
2012-01 | $123.45

Here's a simplified example of what I'd like:

MONTH   | TOTAL REVENUE | DAYS IN MONTH
---------------------------------------
2012-04 | $456.78       | 30
2012-03 | $345.67       | 31
2012-02 | $234.56       | 29
2012-01 | $123.45       | 31

Obviously I'd like this in the form of a formula so I don't need to do any kind of manual tweaking. Is there some kind of formula that can take in 2012-04 and spit out 30?

Best Answer

I use this formula:

=day(eomonth(today(),0))

You'll have to replace today() with a date or a cell containing a date in the month for which you want the total number of days.