VBA Excel Date Calculation

Hi,

I am looking for a way to give me the total number of months between 2 dates, for eg. "2012/03/30 - 2010/09/30"

Please can someone give me the formula that will produce the result of : 18
NerishaBAsked:
Who is Participating?
 
NeilJamesCottonConnect With a Mentor Commented:
There is a function called DateDif

=DATEDIF(A1,B1,"m")

Where A1 and B1 contain the two dates that you want to compare.

Hope this helps.
0
 
ragnarok89Connect With a Mentor Commented:
If the earlier date is in cell A1 and the later date is in cell A2 :-
=DATEDIF(A1,A2,"m")
This will give the rounded down difference in months.

Al
0
 
RunriggerConnect With a Mentor Commented:
datediff("m",datefrom,dateto)
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
RunriggerCommented:
Authors request is for VBA version, correct?
0
 
NeilJamesCottonCommented:
Sorry, you also need to make sure that the Cells that contain dates are formatted as DataType "DATE"

Highlight the cells in question, right click and choose "Format Cells", from the category list, select DATE and also select the display formatting that you want to format the date in. (The type of display formatting shouldn't effect the formulae) as long as you select an option from the DATE category.

Hope this helps
0
 
RunriggerCommented:
Which version of Excel does the DATEDIF function come in at, my company uses Excel 2007 and it does not exist!
0
 
Rory ArchibaldCommented:
DATEDIF is in Excel 2007, just not in the help.
0
 
Rory ArchibaldCommented:
Or in the function dropdown, I just noticed.
0
 
RunriggerCommented:
How bizarre not to have help and/or intellisense for it, do you know the reason, I have written my own UDF because I didn't know it existed!

Is there a master list of "hidden" functions out there Rory?
0
 
Rory ArchibaldCommented:
That's the only one I know of. I don't think anyone outside MS knows why - see Chip's discussion here: http://www.cpearson.com/Excel/datedif.aspx
0
 
NerishaBAuthor Commented:
Thanks guys
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.