Manish Kumawat
Member
Dear Sir,
I have created a user defined function which calculates the year, month and day.
the formula which I have used is:
=CONCATENATE(DATEDIF(A1,A2,"y")," Yr ",DATEDIF(A1,A2,"ym")," M ",DATEDIF(A1,A2,"md")," D")
but the UDF is not providing the same answer as per the formula. Please help me to understand the same.
>>> use code - tags <<<
I have created a user defined function which calculates the year, month and day.
the formula which I have used is:
=CONCATENATE(DATEDIF(A1,A2,"y")," Yr ",DATEDIF(A1,A2,"ym")," M ",DATEDIF(A1,A2,"md")," D")
but the UDF is not providing the same answer as per the formula. Please help me to understand the same.
>>> use code - tags <<<
Code:
Option Explicit
Function mdate(x As Variant, y As Variant)
Dim Fyear As Integer
Dim Fmonth As Integer
Dim FDay As Integer
Fyear = DateDiff("yyyy", x, y)
Fmonth = (DateDiff("M", x, y) / 12 - DateDiff("yyyy", x, y)) * 12
FDay = DateDiff("d", x, y)
mdate = Application.WorksheetFunction.Concat("", Fyear, " Yr, ", Fmonth, " M, ", FDay, " D")
End Function
Last edited by a moderator: