View Full Version : Need Help:-Date Difference
Aryankn
09-17-2015, 07:30 AM
My intention is to find the difference between four dates in two different variables. For e.g.: a=154(15 months and 4 days), b=123 (12 months and 3 days). Now, what I want is a division of
a
-- * x
b
It is basically, division of two dates which needs to be multiplied by a value.
another example that I can quote is
Endate- termination date
------------------------------ * 50
endate-start date
I am achieved till finding the differences of dates into the variables mentioned above.
Can some one please help. I am new to coding and VBA.
Regards,
Aryan
Mal Farrelle
09-17-2015, 08:30 AM
Aryan, assuming that dt1, dt2, dt3 and dt4 are all date variables that contain date values you can assign values to a and b thus:
a = application.datedifference (dt2, dt1)
b = application.datedifference (dt4, dt3)
You will need to trap div by 0 and ensure that dt1 is later than dt2 and that dt4 is later than dt3.
Aryankn
09-17-2015, 01:57 PM
This what I have written
Dim A As Date
Dim B As Date
TXTaftptd.Value = A
TXCPenddt.Value = B
intMonths = Application.datedifference(A, B)
But it throws an error :object does not support property or method.
Mal Farrelle
09-17-2015, 02:07 PM
This what I have written
Dim A As Date
Dim B As Date
TXTaftptd.Value = A
TXCPenddt.Value = B
intMonths = Application.datedifference(A, B)
But it throws an error :object does not support property or method.
You need to assign some values to a and b. And note that the date difference function returns minutes.
This what I have written
Dim A As Date
Dim B As Date
TXTaftptd.Value = A
TXCPenddt.Value = B
intMonths = Application.datedifference(A, B)
Dim A As Date
Dim B As Date
A = CDate(TXTaftptd.Value)
B = CDate(TXCPenddt.Value)
intMonths = Application.DateDiff("m", A, B) ' "m" = Months. "d" = Days. "ww" = Weeks
intWeeks = Application.DateDiff("ww", A, B)
intDays = Application.DateDiff("d", A, B)
ketonen
01-27-2016, 10:51 AM
u solved?
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.