Results 1 to 9 of 9
  1. #1
    Roelkn is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    5

    Dateiff resutl in hh:mm

    Hi,



    I having the following problem
    I have a Table. Whit two Fields named "StartTime" and the other named "EndTime" the date notation dd-mm-yyyy hh:mm:ss

    Now I want to callculate the time difference between the StartTime and EndTime. I Now that I can use the function DateIff only the result that I'am getting is inn hours of Minutes or Seconds.
    I would like it to be hh:mm.

    Hope somone can help solving this problem.

    Greetings Roel Knippen

  2. #2
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Replace your existing expression with Format(expression, "hh:nn")

    Minutes are nn to distinguish from months
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    The difference of dates is just a number - a quantity of elapsed time units, not a date/time value. The Format function will not correctly convert this quantity to hh:nn structure.

    x = DateDiff("n", StartTime, EndTime)

    Int(x/60) & ":" & x mod 60

    The result is a string like 20:36, not a number and not a date/time.

    If you need to do any additional calcs with the DateDiff() calculation such a aggregate sums, don't convert to a string.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    Roelkn is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    5
    Hi Ridder,

    Thank's for the Reply
    When changing the expression to from: test: DateDiff('h';[StartDatumTijd];[EindDatumTijd]) to test1: Format(DateDiff('h';[StartDatumTijd];[EindDatumTijd]);"hh:nn") the result is 00:00. But when I calculated manual it should be 1 hour annd 30 min.

    Hope you can tell me what I am doing wrong.

    Thank's in advance

  5. #5
    Roelkn is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    5
    Hi June,

    Thank's for the reply.
    I'am not a Access specialist. I don't understand where I need to enter the values you are saying.
    Click image for larger version. 

Name:	TEST.png 
Views:	10 
Size:	14.2 KB 
ID:	32554

    Hope the screenshot will make It more clear

    Thank's in advance
    Attached Thumbnails Attached Thumbnails TEST.jpg  
    Last edited by Roelkn; 02-07-2018 at 02:53 AM. Reason: Add screenshot

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Post SQL statement instead of images of design view. Switch the designer to SQL View. Copy/paste statement into post.

    Use "n" instead of "h" in your DateDiff(), then:

    test1: Int([test]/60) & ":" & [test] mod 60


    Added more info to my other post while you were posting.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Roelkn is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    5
    Thank's this was the solution. This the SQL statement I used:

    SELECT Personeel.StartDatumTijd, Personeel.EindDatumTijd, DateDiff('n',[StartDatumTijd],[EindDatumTijd]) AS test, Int([test]/60) & ":" & [test] Mod 60 AS test1
    FROM Personeel;

  8. #8
    Roelkn is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    5
    Hi June,

    Having another question on the above issue. How can I place the result of the above query in a field in my table.

    Hope you can give some advice.

    Thank's in advance

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    It is not necessary to save that calculated data to table, just calculate when needed.

    However, if you must, doing so would require either an UPDATE sql action or binding form to the query and using VBA behind form to save calculated result to field.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

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