Results 1 to 5 of 5
  1. #1
    jlclark4 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Dec 2010
    Location
    North Carolina
    Posts
    155

    Time Difference

    Hey,



    I am attempting to run a query that will give me time difference between ProcessEndB and ProcessStartB. All are in a Date/Time format. I have tried googling several different sites but most give information on subtracting Dates and not Time. Any help is greatly appreciated. I have attached a sample database below.


    Thanks!

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Are "ProcessEndB and ProcessStartB" fields in a Table?

    Are the values contained in them strictly Time values - or do they contain Date AND Time?

  3. #3
    jlclark4 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Dec 2010
    Location
    North Carolina
    Posts
    155
    Hey Robeen,

    ProcessEndB and ProcessStartB are fields in the table (see Example), they are also strictly time.

  4. #4
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    I have never had to calculate the Time Difference between fields before.
    Using the DateDiff function allows you to get either hours, Minutes or Seconds.

    Try this SQL in your query.
    In design view, Click 'View', 'SQL View', and then paste this in:

    Code:
     
    SELECT tblCities.EntryNumber, tblCities.City, tblCities.ProcessStartA, tblCities.ProcessStartB, tblCities.ProcessEndB, DateDiff("h",[ProcessStartB],[ProcessEndB]) AS TimeElapsedHours, DateDiff("n",[ProcessStartB],[ProcessEndB]) AS TimeElapsedMinutes, DateDiff("s",[ProcessStartB],[ProcessEndB]) AS TimeElapsedSeconds
    FROM tblCities;
    This will show you that you can get the time difference in three different formats.

    If you want to see something like this for the elapsed time:
    04:17:53
    You might consider creating a Function and sending it your start & end times and then doing the Math in the Function.

    You would 'call' the function from your query and pass it the start and end times.

    Let me know if you need help.

  5. #5
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    What do you want your output to look like. If there's a possibility that the time will go into days/weeks/months you there is no standard format for that.

    If your times will always be in a number of hours, minutes and seconds you'd have to build an expression. Secondly there's no real reason to store your date/time as two separate fields, it's just going to make things more complicated for your calculation.

    I change your table to have two new fields

    PROCESSSTART
    PROCESSEND

    each is a date/time field and instead of keeping the day and time separate I joined the values you have in there into a single field then I used this SQL statement to build a query. I left everything in separate fields so you could see how it went together:

    Code:
    SELECT tblCities.EntryNumber, tblCities.City, tblCities.ProcessStart, tblCities.ProcessEnd, DateDiff("s",[processstart],[processend]) AS SecDiff, Int([secdiff]/86400) AS Days, Int([secdiff]/3600)-([days]*24) AS Hours, Int([secdiff]/60)-([hours]*60)-([days]*1440) AS Minutes, [secdiff]-([minutes]*60)-([hours]*3600)-([days]*86400) AS Seconds
    FROM tblCities;

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

Similar Threads

  1. HELP! Elapsed Time Difference
    By accessineedhelp in forum Access
    Replies: 5
    Last Post: 08-31-2011, 06:00 PM
  2. working out time difference
    By moonman84 in forum Reports
    Replies: 1
    Last Post: 07-31-2011, 05:37 AM
  3. working out time difference
    By moonman84 in forum Access
    Replies: 2
    Last Post: 06-29-2011, 03:33 AM
  4. Mark the difference
    By zhshqzyc in forum Access
    Replies: 1
    Last Post: 01-28-2011, 08:49 AM
  5. Time difference
    By jguidry in forum Programming
    Replies: 1
    Last Post: 11-15-2008, 12:41 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