Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Access (https://www.askmehelpdesk.com/forumdisplay.php?f=441)
-   -   Time Calculation (https://www.askmehelpdesk.com/showthread.php?t=295390)

  • Dec 24, 2008, 03:37 AM
    gwallace1
    Time Calculation
    How do you get Access to add time when the time can span over two or meore days. I have a start date field, an End Date field as well as a start and end time field. For instance if I start on 01/01/2009 at 0600 and end on 01/02/2009 at 1800 I need access to tell me the sum is 32 hours... Any way to do this? Also where should this calculation take place if I want it to be a stored value? Thanks in advance.

    GW
  • Dec 24, 2008, 07:53 AM
    ScottGem

    First you need to understand how Access stores date/time values. Date/time values are stored as a double precision number where the integer portion is the number of days since 12/30/1899 and the decimal portion is a fraction of a day (ex: 6AM or 6 hrs = .25)

    So, if you need to do time arithmetic you need to store the date and time together. The second key is to use the Date Diff function and calculate time in terms of the precision you need. The Datediff function will calculate the time difference in terms of hours, minutes or seconds. Once you get the difference, you can then display the time as a text string. For example, assuming you get the difference in minutes, lets modify your example and say the time span goes from 1/1 0600 to 1/2 1830. This would total 1950 minutes. So you could use the expression:

    =Int(DateDiff("n",time1,time2)/60) & ":" & DateDiff("n",time1,time2) MOD 60
    This would display 32:30

    As a general rule we do not store calculated values, so you could use this exptression to display the difference wherever needed.

  • All times are GMT -7. The time now is 08:07 PM.