get diff in access 2007 between two dates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Blerta

    #1

    get diff in access 2007 between two dates

    Please can you help me, I have two dates e.x:2008_11 and 1999_02 and i want to get the difference between these two dates in months or in years, please can you help me solve this?
    Thank you!
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Ahh, but these are not dates; if they were, you could have used the built-in DateDiff function to compute the difference for you.

    The values you show are text strings, and you can manipulate these using the Left and Right functions to extract the year and month components accordingly, and the Val function to take the numeric value of these text substrings.

    The year and the month can be recovered from the string like this:

    Code:
    Val(Left([name of the field concerned], 4)) 
    Val(Right([name of the field concerned], 2))
    Once you've got these you can manipulate the result to find the difference between two such values. I leave it for you to work out how to do this once you've extracted the year and month components for each 'date' concerned.

    -Stewart

    Comment

    • Blerta

      #3
      Thank you Stewart, it works but only for years, because for months it gives me the difference between months like they were in the same year.
      Anyway it was very helpful and i used only year_diff.
      Thanks

      Comment

      Working...