Calculating dates

D

Dimas

Is it possible to calculate the difference in months
between two different years? Example how many months
between today's date and december of any year not
including the number oy years? Example between May of
2003 and April 2003 are 13 months, but in reality there
is only one month between April and May.
 
J

Jim Cone

Dimas

This seems to work...
=ABS(MONTH(B1)-MONTH(A1))

This custom function returns the name of the month that is M months away (+
or -)...
'------------------------------------------
Function THEMONTH(ByVal M As Long) As String
On Error GoTo NoDate
Dim Months As Variant
Dim PickOne As Integer
Months = Array("December", "January", "February", "March", "April",
"May", _
"June", "July", "August", "September", "October",
"November")
PickOne = (M + Month(Date)) Mod 12
If PickOne >= 0 Then THEMONTH = Months(PickOne) Else _
THEMONTH = Months(PickOne + 12)
Exit Function

NoDate:
THEMONTH = "Error " & Err.Number
End Function
'------------------------------------------
Regards,

Jim Cone
San Francisco, CA
*******************************
 
L

Lance

another thought
create a function

Function dd(a As Date, b As Date)
Application.Volatile
dd = DateDiff("m", a, b)
End Function
 

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