Results 1 to 2 of 2
  1. #1
    2 Star Lounger
    Join Date
    May 2002
    Bristol, Avon, England
    Thanked 0 Times in 0 Posts

    Detediff for working days with negative difference (2000)

    This is probably an old chestnut but I'm still confused.

    I know that Datediff doesn't work for working days. I have the Microsoft KB DatediffW function. However it does not seem to work when you want to calculate negative differences as well as positive ones.
    eg I want to be able to show the difference between
    start date - #12/09/03#
    end date - #08/09/03#

    as -4 days not 0 days.

    Any ideas?

  2. #2
    Star Lounger
    Join Date
    Aug 2001
    Thanked 0 Times in 0 Posts

    Re: Detediff for working days with negative difference (2000)

    Check before you use the DateDiff to see if the start date is greater than the end date. Set a flag if it is, so you can then return a negative number if needed.

    dim fNegNumber as boolean

    fNegNumber = (StartDate > EndDate )
    If fNegNumber then
    'Swap the dates in the tempDates so DateDiff will work.
    tempStartDate = EndDate
    tempEndDate = StartDate
    ' Pass them as they are...
    tempStart = StartDate
    tempEndDate = EndtDate
    End If

    'use the TempDates with the DateDiff here to return the number of days
    NumOfDays = Datediff(..use the two tempDates as args here.........)

    If fNegNumber then
    NumOfDays = NumOfDays * -1
    End If

Posting Permissions

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