If statement to compare months in a date

W

whiZZfiZZ

Hi everyone, i am hoplessly stuck on what is probably a simple littl
fomula and was hoping someone might be able to help me please.

I have two dates.
One in B5 (say 31/05/04
One in A11 (say 22/05/04)

what im trying to so is, if the months are the same (ie they are bot
may) then i want excel to work out the number of days between each one
if the month is not the same (say that B5 is 30/06/04), i want excel t
tell me how many days are in the current month (ie 30 days in June)

(the date in B5 will always be greater than the date in A11)

here is my formula:

=IF(Date(Month(B5))=Date(MONTH(A11)),B5-A11,DAY(DATE(YEAR(b5),MONTH(b5)+1,0))

I dont understand what im doing wrong
doh!!!!

any help would be greatly appreciated.
thank you
 
W

whiZZfiZZ

i knew it was something simple (shakes head)


thanks for your help Andy
cheers mate.

Andy said:
Hi

Try this:
=IF(MONTH(B5)=MONTH(A11),B5-A11,DAY(DATE(YEAR(B5),MONTH(B5)+1,0)))
 
J

Juan Sanchez

This worked for me:


=IF(MONTH(B5)=MONTH(A11),B5-A11,DAY(DATE(YEAR(B5),MONTH(B5)
+1,0)))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top