PDA

View Full Version : Calculating difference between months



arrun
06-25-2014, 12:22 PM
Hi,

Assume I have a base-string 'May-2014' and few other related strings in a target array i.e. 'Jul-2014', 'Nov-2014', 'Dec-2014'. Now I want to calculate the number of months between base-string and target-array. Therefore I want to get an array of integer like 2, 6, 7

Is there any VBA function available to achieve that?

Thanks for your pointer.

westconn1
06-25-2014, 02:37 PM
just subtracting the month will only work within the same year, so use a date function
try like

= datediff("m","may-2013","jul-2014")

arrun
06-25-2014, 02:56 PM
Is that excel function? I am getting #NAME? error in excel.

p45cal
06-25-2014, 03:51 PM
Is that excel function? I am getting #NAME? error in excel.No, it's a vba function.
The sheet function is
= DATEDIF("may-2013","jul-2014","m")
see here (http://www.cpearson.com/excel/datedif.aspx) for documentation.