Results 1 to 6 of 6
  1. #1
    siapliw is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    13

    Calculating days & Time


    Hi,
    I tried different datediff formulas & could not succeed to get the appropriate result.
    I want the result in Days, hours & minutes.

    I tried the following code, which gives the result in minutes.
    =DateDiff("n",[2IPPVstartDate]+[2IPPVstartTime],[2IPPVfinisDate]+[2IPPVfinishTime])\60 & Format(DateDiff("n",[2IPPVstartDate]+[2IPPVstartTime],[2IPPVfinishDate]+[2IPPVfinishTime]) Mod 60,"\:00")
    Please help.

  2. #2
    GeekInOhio's Avatar
    GeekInOhio is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2012
    Posts
    25

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    The very clever Diff2Dates hack by Doug Steele and Graham Seach, which can be found on the Access MVP site at

    http://www.accessmvp.com/djsteele/Diff2Dates.html

    makes it easy to do the type of calculations you want here, as well as others, using the Access native Datediff() Function. It allows you to get an elasped time in a number of different formats, such as Days/Hours/Minutes or Years/Months/Days, etc, but the underlying logic is really simple.

    You calculate the difference between to points in time, in the lowest common denominator you're interested in (i.e. the smallest unit of time you want to report, in this case Hours) and then parse it out:

    Hours = DateDiff("h", [StartDateTime], [EndDateTime])

    so

    Days = DateDiff("h", [StartDateTime], [EndDateTime])\24

    and

    HoursLeft = DateDiff("h", [StartDateTime], [EndDateTime]) Mod 24

    Then to display it in the format 00:00, as you originally requested, you could use a Control Source of

    =[Hours] \ 24 & Format([Hours] Mod 24, "\:00")

    Or

    =[Days] & Format([HoursLeft], "\:00")

    in a Field that is defined as Text, to accommodate the non-numerical characters.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    siapliw is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    13
    Is it possible to build 3 arguments here? What I want is D:MM:HH.
    DateDiff("h", [StartDateTime], [EndDateTime])\24
    & Format([Hours] Mod 24, "\:00") gives MM:HH result
    What I'm missing?
    Cheers.

  5. #5
    GeekInOhio's Avatar
    GeekInOhio is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2012
    Posts
    25
    I'd just use this, but I tend to get a bit lazy with these things.

    http://msdn.microsoft.com/en-us/library/aa227535(v=vs.60).aspx

  6. #6
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by siapliw View Post
    ...What I want is D:MM:HH.
    Sorry for taking so long to get back to you; in the middle of getting a daughter married and lost track of some threads!

    Assumming that D:MM:HH is supposed to be D:HH:MM or Days:Hours:Minutes, this works for me:
    Code:
    DateDiff("n", [StartDateTime], [EndDateTime]) \ 1440 & ":" & (DateDiff("n", [StartDateTime], [EndDateTime]) Mod 1440) \ 60 & ":" & DateDiff("n", [StartDateTime], [EndDateTime]) Mod 60
    I've inserted the Field Names you gave in your last post.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Replies: 8
    Last Post: 08-24-2012, 01:54 AM
  2. Replies: 3
    Last Post: 02-24-2012, 01:23 PM
  3. Replies: 4
    Last Post: 09-06-2011, 02:20 PM
  4. Calculating Time
    By jlclark4 in forum Forms
    Replies: 0
    Last Post: 04-25-2011, 09:04 AM
  5. Replies: 12
    Last Post: 02-22-2011, 03:39 PM

Tags for this Thread

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