Results 1 to 8 of 8

Thread: The Number of Years, Months and Days Between Two Dates

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Senior Member
    Join Date
    Jun 2012
    Posts
    337
    Rep Power
    13

    datediff different

    Hi Rick,

    Nice function you wrote.
    You challenged me to do so too.

    Wouldn't this suffice ?

    Code:
    Function snb(x0 as string, x1 as string)
        x2 = DateDiff("m", x0, x1) - IIf(Day(x0) > Day(x1), 1, 0)
        c01 = x2 \ 12
        c02 = x2 Mod 12
        c03 = Day(x1) - Day(x0) + IIf(Day(x1) >= Day(x0), 0, Day(CDate(x1) - Day(x1)))
        snb = c01 & " year" & IIf(c01 = 1, ", ", "s, ") & c02 & " month" & IIf(c02 = 1, ", ", "s, ") & c03 & " day" & IIf(c03 = 1, "", "s")
    End Function
    Code:
    sub tst()
      msgbox snb("02-04-2011","22-02-2012")
    end sub
    Last edited by snb; 06-08-2012 at 12:33 PM.

Similar Threads

  1. Replies: 0
    Last Post: 09-17-2012, 02:05 PM
  2. How to Extracting dates and days between 2 dates.
    By Rajesh Kr Joshi in forum Excel Help
    Replies: 9
    Last Post: 08-11-2012, 09:11 PM
  3. Excel Datedif - Days of February
    By Excelfun in forum Excel Help
    Replies: 6
    Last Post: 06-10-2012, 02:32 PM
  4. Visual Plotter basis given dates and activity
    By Rajesh Kr Joshi in forum Excel Help
    Replies: 2
    Last Post: 03-07-2012, 02:37 PM
  5. Number of Days In A Month
    By Excel Fox in forum Excel and VBA Tips and Tricks
    Replies: 0
    Last Post: 05-14-2011, 08:00 PM

Posting Permissions

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