Consulting

Results 1 to 6 of 6

Thread: Need Help:-Date Difference

  1. #1
    VBAX Newbie
    Joined
    Sep 2015
    Posts
    2
    Location

    Need Help:-Date Difference

    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

  2. #2
    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.

  3. #3
    VBAX Newbie
    Joined
    Sep 2015
    Posts
    2
    Location
    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.

  4. #4
    Quote Originally Posted by Aryankn View Post
    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.

  5. #5
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    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)
    Last edited by SamT; 09-17-2015 at 03:45 PM.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  6. #6
    VBAX Regular
    Joined
    Jan 2016
    Posts
    7
    Location
    u solved?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •