Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    stavros is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Posts
    17

    DateDiff function

    I am trying to calculate how many days are left till end of contract...



    whats wrong with this formula

    =DateDiff("d",[Completion_Date], Date())

    Click image for larger version. 

Name:	Datediff.png 
Views:	16 
Size:	34.6 KB 
ID:	12404

  2. #2
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    I am not sure.
    I do know that this would be better done in a query.
    Calculated fields can cause problems later on in your development of your data base.

    Dale

  3. #3
    stavros is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Posts
    17
    Quote Originally Posted by rzw0wr View Post
    I am not sure.
    I do know that this would be better done in a query.
    Calculated fields can cause problems later on in your development of your data base.

    Dale
    it doesn't work in query either...

    Time_left: DateDiff("d",[Completion_Date], Date())

    Click image for larger version. 

Name:	Untitled.png 
Views:	11 
Size:	41.9 KB 
ID:	12572
    any help?

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Would you post the SQL of the query? The picture doesn't show the expression.

    This worked for me:
    Code:
    SELECT ImportTest.Text1, ImportTest.Text2, ImportTest.Date_Time, DateDiff("d",[date_time],Date()) AS TimeLeft
    FROM ImportTest;
    With the [Date_Time] = 5/1/2013, and Date() =5/31/2013 (today), the result is 30.

  5. #5
    stavros is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Posts
    17
    SELECT Contracts.Contract_ID_No, Contracts.Contract_Name, Contracts.Start_Date, Contracts.Completion_Date
    FROM Contracts;

    This formula doesn't work... Time_left: DateDiff("d",[Completion_Date], Date())

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850
    How is completion_date defined? Is it date/Time datatype?
    It seems you don't need the equal signs for a calculated field.

  7. #7
    stavros is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Posts
    17
    completion_date is defined as date/time (Short date)...

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850

  9. #9
    stavros is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Posts
    17
    i am using access only several times, learning from youtube, so please be patient :-)

    where is it equal(=) sign in this Time_left: DateDiff("d",[Completion_Date], Date())

  10. #10
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850
    I was suggesting you remove the equal sign when using the function as a calculated field in your table.

    I don't understand why your expression is not working in the query.

  11. #11
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I made a table using the fields in your SQL, then added a couple of records. I used your query and added the date diff function. No errors....

    field name - field type
    ----------------------
    Contract_Name - text
    Start_Date - date/time
    Completion_Date - date/time



    Here is the query:
    Code:
    SELECT Contracts.Contract_ID_No, Contracts.Contract_Name, Contracts.Start_Date, Contracts.Completion_Date, DateDiff("d",[Completion_Date],Date()) AS Time_left
    FROM Contracts;
    Create a new query, switch to SQL view, paste in the above SQL statement and execute the query.

  12. #12
    stavros is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Posts
    17
    the query with past text from ssanfu post is working. only for contracts that are not finished jet time left is negative number while contracts that are finished left time is positive number... for those past contract it would be better that is written contract finished... and left time should be positive number

  13. #13
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Not sure what you are asking...

    How do you tell if a contract is finished?

    If the contract is not finished, and you want the number to be positive, swap the dates:
    Code:
    DateDiff("d",Date(),[Completion_Date]) AS Time_left

  14. #14
    stavros is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Posts
    17
    Quote Originally Posted by ssanfu View Post
    Not sure what you are asking...

    How do you tell if a contract is finished?

    If the contract is not finished, and you want the number to be positive, swap the dates:
    Code:
    DateDiff("d",Date(),[Completion_Date]) AS Time_left
    thx. done by my self... now i have to do automatic email those persons which contract is expiring within 45 days and repeat within 30 days...

    SELECT Contracts.Contract_ID_No, Contracts.Contract_Name, Contracts.Start_Date, Contracts.Completion_Date, IIf(DateDiff("d",Date(),[Completion_Date])<0,"contract expires",DateDiff("d",Date(),[Completion_Date])) AS Time_leftFROM Contracts;

  15. #15
    stavros is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Posts
    17
    for one contract it can be several contractors (joint venture)... while in query same contract is repeating for each contractor in JV.

    how could i change it that one contract in written only once and in column contractors is listed several firms?

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. DateDiff Function
    By Nixx1401 in forum Access
    Replies: 4
    Last Post: 04-14-2011, 09:27 AM
  2. DateDiff
    By ROB in forum Access
    Replies: 2
    Last Post: 10-30-2010, 03:58 AM
  3. Need Help with Datediff
    By gonzod in forum Access
    Replies: 5
    Last Post: 08-26-2010, 02:29 PM
  4. Datediff
    By greggue in forum Queries
    Replies: 2
    Last Post: 08-13-2010, 03:53 PM
  5. DateDiff function
    By Scott R in forum Reports
    Replies: 5
    Last Post: 12-03-2008, 07:32 AM

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