Results 1 to 5 of 5
  1. #1
    Delta729 is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Location
    Los Angeles
    Posts
    95

    DateDiff for Months

    I could use some help, because I am not finding a good way to do this. I have a table with [Contract Start Date] and [Contract End Date]. In my query, I have the following:



    Contract Duration: DateDiff("m",[tblObjective]![Contract Start Date],[tblObjective]![Contract End Date]) & " Months"

    The issue is that if a contract starts on 9/1/14 and ends on 12/31/14, it's showing 3 months. After reading several articles on Google, I guess I understand why. Is there an easy way for this to show as 4 months?

  2. #2
    Delta729 is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Location
    Los Angeles
    Posts
    95
    I also need to say that I'm not a big user of Access, and really a complete novice if the answer if VB code. So, hopefully this isn't too difficult. Also, maybe Datediff is just the wrong thing to be using and maybe some function was designed for this that I couldn't find?

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    IF the contract end date will ALWAYS be the last day of the month, you can add 1 day to the contract end date.

    Try this query
    Code:
    SELECT tblObjective.[Contract Start Date], tblObjective.[Contract End Date], DateDiff("m",tblObjective.[Contract Start Date],tblObjective.[Contract End Date]) & " Months" AS [Contract Duration], DateDiff("m",tblObjective.[Contract Start Date],tblObjective.[Contract End Date]+1) & " Months" AS [Contract Duration2]
    FROM tblObjective;

  4. #4
    Delta729 is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Location
    Los Angeles
    Posts
    95
    Thanks for the reply, unfortunately the contract end date can be any day of the month.

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Please fill in what you say the number of months should be
    Row Start End Months
    1 9/1/2014 12/1/2014 =
    2 9/1/2014 12/10/2014 =
    3 9/1/2014 12/20/2014 =
    4 9/1/2014 12/31/2014 =

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

Similar Threads

  1. Replies: 3
    Last Post: 02-23-2014, 02:06 PM
  2. DateDiff Help
    By iProRyan in forum Forms
    Replies: 1
    Last Post: 03-29-2012, 03:57 AM
  3. DateDiff
    By mrkaye in forum Forms
    Replies: 18
    Last Post: 11-19-2010, 08:19 AM
  4. DateDiff
    By ROB in forum Access
    Replies: 2
    Last Post: 10-30-2010, 03:58 AM
  5. How to use DateDiff?
    By teirrah1995 in forum Queries
    Replies: 10
    Last Post: 10-19-2010, 12:07 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