Results 1 to 4 of 4
  1. #1
    Starmo is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2018
    Posts
    43

    Calculating the difference in months


    Hello everyone!
    How to calculate the number of months between a date and today and to multiply the number of months obtained by multiplying it by some number.
    Thanks!

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Use the Month and Date functions. e.g.
    Code:
    Month(#11/8/2017#)-Month(Date())
    Result = 5

    To multiply that by e.g. 5, its
    Code:
    5*(Month(#11/8/2017#)-Month(Date()))
    P.S. Welcome to the forum
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    Starmo is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2018
    Posts
    43
    Thanks for the welcome!
    At my quaery this code is not working. Maybe because the date is set in dd.mm.yyyy in me?
    This is all related to the query of "Help for my problem". I was trying to do something ...

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    When using dates in VBA code you have to convert the dates to mm/dd/yyyy or yyyy-mm-dd format
    Unless you do so, results will be unpredictable

    So use something like this:
    Code:
    Month(Format(mydate,"mm/dd/yyyy"))-Month(Date())
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Calculating Date Difference
    By awhittle23 in forum Programming
    Replies: 29
    Last Post: 08-03-2016, 04:33 PM
  2. Calculating 5 months
    By keiath in forum Forms
    Replies: 3
    Last Post: 01-24-2014, 12:25 PM
  3. Replies: 1
    Last Post: 07-10-2012, 06:23 AM
  4. Replies: 10
    Last Post: 12-27-2011, 01:20 PM
  5. Replies: 1
    Last Post: 12-14-2011, 05:35 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
  •  
Other Forums: Microsoft Office Forums