Consulting

Results 1 to 3 of 3

Thread: datediff function

  1. #1
    VBAX Mentor
    Joined
    Jun 2005
    Posts
    374
    Location

    datediff function

    hello
    i am trying to use a select case statment with a datediff function:
    Function dayDiff(dte1 As Date, dte2 As Date, basis)
    Select Case basis
    Case ww
    dayDiff = DateDiff("ww", dte1, dte2)
    Case d
    dayDiff = DateDiff("d", dte1, dte2)
    Case m
    dayDiff = DateDiff("m", dte1, dte2)
    Case q
    dayDiff = DateDiff("q", dte1, dte2)
    End Select
    End Function
    what went wrong?
    thanks
    moshe
    moshe

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by lior03
    hello
    i am trying to use a select case statment with a datediff function:
    Function dayDiff(dte1 As Date, dte2 As Date, basis)
    Select Case basis
    Case ww
    dayDiff = DateDiff("ww", dte1, dte2)
    Case d
    dayDiff = DateDiff("d", dte1, dte2)
    Case m
    dayDiff = DateDiff("m", dte1, dte2)
    Case q
    dayDiff = DateDiff("q", dte1, dte2)
    End Select
    End Function
    what went wrong?
    thanks
    moshe
    [vba]
    Function dayDiff(dte1 As Date, dte2 As Date, basis)
    Select Case basis
    Case "ww"
    dayDiff = DateDiff("ww", dte1, dte2)
    Case "d"
    dayDiff = DateDiff("d", dte1, dte2)
    Case "m"
    dayDiff = DateDiff("m", dte1, dte2)
    Case "q"
    dayDiff = DateDiff("q", dte1, dte2)
    End Select
    End Function
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    Couldn't you just do

    [VBA]Function dayDiff(dte1 As Date, dte2 As Date, basis)
    dayDiff = DateDiff(basis, dte1, dte2)
    End Function[/VBA]

    ??

Posting Permissions

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