Take the 2-minute tour ×
Web Applications Stack Exchange is a question and answer site for power users of web applications. It's 100% free, no registration required.

The title kind of says it all but just to give you the use case, I have a spreadsheet where I track monthly ad 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?

share|improve this question
add comment

3 Answers

I stumbled across the EOMONTH function which is exactly what I needed, I end up doing a bunch of substring stuff but it seems to work which is all that is important to me.

Here's an example that will get you the number of days in field A2 assuming it's in YYYY-MM format

=LEFT(RIGHT(EOMONTH(RIGHT(A2,2)&"/01/"&LEFT(A2,4),0),7),2)
share|improve this answer
add comment

Parsing a Date with Left and Right might be unreliable (for example, in case the data format changes).

You could simplify the formula by using the DAY function instead:

=DAY( EOMONTH(RIGHT(A2,2)&"/01/"&LEFT(A2,4),0) )

Also the way you compose the date inside the EOMONTH call could be replaced, using the DATE(<year>, <month>, <day>) function to make it a little more reliable.

So, the final formula would become:

=DAY( EOMONTH( DATE(LEFT(B51,4), RIGHT(B51,2), 1) ,0) )
share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.