Results 1 to 6 of 6

Thread: date diff

  1. #1
    Join Date
    Apr 2013
    Posts
    4

    Unanswered: date diff

    This should be easy. But I cannot get it right.

    I have 2 date fields. General Date - Format m/d/yy hh:mm
    I want to create a query that will return the difference between the dates in HH:MM

    So I figured this would work

    SELECT DateDiff(hh,Field2,Field1) AS 'diff'
    FROM dateTest;

    But it prompts me for an hh value.

    Can anyone help me out with this.

    thanks

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    DateDiff Function - Access - Office.com
    suggests it should be
    SELECT DateDiff("hh",Field2,Field1) AS 'diff'
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Apr 2013
    Posts
    4
    If I do this

    SELECT DateDiff("hh",Field2,Field1) AS ['diff']
    FROM dateTest;

    I get a #Func! result

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    SELECT DateDiff("hh",Field2,Field1) AS diff
    ..no need for the square brackets if there are no spaces in the table / column name
    ..also I missed the quotes around diff.. that would suggest the results would go to a litteral value as opposed to what you want an aliased column
    whilst you are at it check field2 and field 1 are both of date time datatype AND check that field2 is before field1

    I'd also suggest you get in the habit of giving your columns meaningful names
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Apr 2013
    Posts
    4
    Quote Originally Posted by healdem View Post
    SELECT DateDiff("hh",Field2,Field1) AS diff
    ..no need for the square brackets if there are no spaces in the table / column name
    ..also I missed the quotes around diff.. that would suggest the results would go to a litteral value as opposed to what you want an aliased column
    whilst you are at it check field2 and field 1 are both of date time datatype AND check that field2 is before field1

    I'd also suggest you get in the habit of giving your columns meaningful names

    Thanks for the help.
    I am still having problems with the #Func


    I created a new table DateTable
    With 2 Date/Time fields Start End

    Start - 4/7/2013
    End - 4/25/2013

    I created a new query
    SELECT DateDiff("hh",End,Start) AS TimeDifference
    FROM DateTable;


    Still #Func!

    Any ideas

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    suggest you re read the reference in post #2 and make certain you are calling the function with the correct paraeters
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •