Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8149083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:46:39+00:00 2026-06-06T14:46:39+00:00

DateDiff calculates incorrect: DateDiff(m, 30/06/2011, 24/06/2012) will return 12 But i need to return

  • 0

DateDiff calculates incorrect:

DateDiff("m", "30/06/2011", "24/06/2012") will return 12

But i need to return 11,because real difference is 11 months and 25 days

Maybe anyone have specific solution for this question

That will be ideal for me: 11 months and 25 days

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:46:40+00:00Added an answer on June 6, 2026 at 2:46 pm

    Here’s a cleaner solution than the above custom made function. Mostly it uses the built-in DateDiff function, but then adjusts the answer if it rounds up.
    My function will also give you the difference even if the the first date is later than the second and optionally add some text saying so.

    Function YearsMonthsDays(Date1 As Date, _
                         Date2 As Date, _
                         Optional ShowAll As Boolean = False, _
                         Optional Grammar As Boolean = True, _
                         Optional MinusText As String = "Minus " _
                         ) As String
    Dim dTempDate As Date
    Dim iYears As Integer
    Dim iMonths As Integer
    Dim iDays As Integer
    Dim sYears As String
    Dim sMonths As String
    Dim sDays As String
    Dim sGrammar(-1 To 0) As String
    Dim sMinusText As String
    
    If Grammar = True Then
        sGrammar(0) = "s"
    End If
    
    
    If Date1 > Date2 Then
        dTempDate = Date1
        Date1 = Date2
        Date2 = dTempDate
        sMinusText = MinusText
    End If
    
    iYears = DateDiff("yyyy", Date1, Date2)
    Date1 = DateAdd("yyyy", iYears, Date1)
    If Date1 > Date2 Then
        iYears = iYears - 1
        Date1 = DateAdd("yyyy", -1, Date1)
    End If
    
    iMonths = DateDiff("M", Date1, Date2)
    Date1 = DateAdd("M", iMonths, Date1)
    If Date1 > Date2 Then
        iMonths = iMonths - 1
        Date1 = DateAdd("m", -1, Date1)
    End If
    
    iDays = DateDiff("d", Date1, Date2)
    
    If ShowAll Or iYears > 0 Then
        sYears = iYears & " year" & sGrammar((iYears = 1)) & ", "
    End If
    If ShowAll Or iYears > 0 Or iMonths > 0 Then
        sMonths = iMonths & " month" & sGrammar((iMonths = 1)) & ", "
    End If
    sDays = iDays & " day" & sGrammar((iDays = 1))
    
    YearsMonthsDays = sMinusText & sYears & sMonths & sDays
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I use DATEDIFF to return the difference between two dates in years,
I need to calculate date difference using flowing query but it does not work.
I need to calculate the difference (in days) between two dates in MySQL excluding
Datediff calculates the no of months between two dates, Is there any function which
I really need help on this those function DATEDIFF OR DateAdd , because I
I need to calculate the DateDiff (hours) between two dates, but only during business-hours
I need to calculate the difference between two timestamps in milliseconds. Unfortunately, the DateDiff-function
I need to calculate the year diferences between two dates. Tried using DATEDIFF but
i need to perform an operation (in this case DATEDIFF()) on 2 dates. But
I have a report that calculates multiple date differences (in business days, not DATEDIFF)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.