Results 1 to 8 of 8
  1. #1
    Creaturemagic is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    May 2013
    Posts
    4

    SQL Query, find difference in two times.

    So for a School project I have to design a database for a cab company, and I wanted to make a query to calculate the time difference between when the customer calls and when the driver arrives. However both fields are date/time fields, and I am unsure of the SQL query to calculate this.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    I've written a couple of taxi apps. If those are both fields in the same record, you can just use the DateDiff() function.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Creaturemagic is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    May 2013
    Posts
    4
    Quote Originally Posted by pbaldy View Post
    I've written a couple of taxi apps. If those are both fields in the same record, you can just use the DateDiff() function.
    With Datediff() as far as I know I have to type the dates in, don't I?
    I don't want to have to type each time in and make like 30+ queries, is there a way to make it automatically select the two matching times from each field and find the difference.
    Maybe I can do that, I'm just unsure how?
    Also, I just tried a normal Datediff, this one:
    SELECT DATEDIFF (Minute, '10:57:00', '11:02:00')
    Access 2007 told me "Minute" needed a parameter.

    Thanks for any help

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    No, you can simply refer to the 2 fields. Check help for the proper syntax; you've got the SQL Server syntax there.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Creaturemagic is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    May 2013
    Posts
    4
    Quote Originally Posted by pbaldy View Post
    No, you can simply refer to the 2 fields. Check help for the proper syntax; you've got the SQL Server syntax there.
    This is the right code:
    SELECT [Driver_ID], DATEDIFF(minute, [Request_Time], [Start_Time]) AS [Time Taken in minutes]
    FROM Jobs

    Yet Access still says "Enter parameter value... Minute"
    According to Microsoft my code is correct: http://msdn.microsoft.com/en-us/library/ms174630.aspx
    But for some reason it does not work

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    You didn't notice that says SQL Server at the top? You want "n" there, with the quotes.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Creaturemagic is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    May 2013
    Posts
    4
    Quote Originally Posted by pbaldy View Post
    You didn't notice that says SQL Server at the top? You want "n" there, with the quotes.
    Dude thanks so much! You're a genius!

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    No problemo. Welcome to the site by the way!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Difference between Dates/Times
    By dr4ke in forum Queries
    Replies: 3
    Last Post: 06-26-2012, 06:30 AM
  2. DateTime Difference Query help?
    By Astron2012 in forum Queries
    Replies: 6
    Last Post: 04-27-2012, 10:24 PM
  3. Replies: 3
    Last Post: 07-05-2011, 02:25 PM
  4. Replies: 1
    Last Post: 04-14-2011, 07:19 AM
  5. Replies: 3
    Last Post: 08-07-2010, 06:05 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