Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 510
  • Last Modified:

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
0
NerishaB
Asked:
NerishaB
  • 4
  • 3
  • 2
  • +2
3 Solutions
 
NeilJamesCottonCommented:
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
 
ragnarok89Commented:
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
 
RunriggerCommented:
datediff("m",datefrom,dateto)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now