Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2014
    Posts
    7

    Unanswered: DateDiff - Syntax error - Plz help!

    I tried
    DateDiff("d", [Date Closed], [Date Created])
    and
    =DateDiff("d", [Date Closed], [Date Created])
    and
    DifferencField=DateDiff("d", [Date Closed], [Date Created])
    and
    DifferencField: DateDiff("d", [Date Closed], [Date Created])

    i get an error about the syntax / compilation


    both
    [Date Closed] and [Date Created] are date (not text or other) field types.

    I want to compare the number of days between date close and date created and dislay/enter the value of the number of days difference, so if dates are the same we get a 0, closed on a second day we get 1, etc.

    whats wrong with the syntax
    Last edited by Being; 02-14-14 at 17:29.

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    You haven't said where you're trying to use it, but the basic syntax is fine. Just tested this in a query:

    Test: DateDiff("d",[CallDateTime],[ReqDateTime])
    Paul

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    the syntax looks fine
    you assert that both [Date Closed] and [Date Created] are date (not text or other) field types.

    what id suggest you do is put a break on the code and examine the values
    int he immediate window type ?isdate([date closed]) and the smae for date open
    or
    avalue =DateDiff("d", cdate([Date Closed]), cdate([Date Created]))
    or explicitly cast the values to variables that are of type date
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    As Paul said, you haven't really said where you're trying to do this, and the where is important, because the syntax does vary, accordingly. Also, you use

    DifferencField

    as a name...is that correct? Or should it be

    DifferenceField

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    Join Date
    Feb 2014
    Posts
    7
    DifferenceField is just a column name you could call it whatever you want.

    i am putting the query in Acesss.. I opened the table in design view, i created a new field and selected Calculated type, for the expression i typed the code.. throws a syntax error.

    so to edit, i click on the expression button next to the expression field under the General tab and open the Expression Builder

    i have this in right now and its not working
    days2close: DateDiff("d", [Date Closed], [Date Created])

  6. #6
    Join Date
    Feb 2014
    Posts
    7
    here is where i am writing the code which throws a syntax error

    imgur: the simple image sharer

  7. #7
    Join Date
    Feb 2014
    Posts
    7

    Plz help me calculate difference in 2 dates

    Trying to calculate the difference between 2 dates
    i get a syntax error

    I tried
    DateDiff("d", [Date Closed], [Date Created])
    and
    =DateDiff("d", [Date Closed], [Date Created])
    and
    DifferenceField=DateDiff("d", [Date Closed], [Date Created])
    and
    dude: DateDiff("d", [Date Closed], [Date Created])
    and
    dudePlease= DateDiff("d", cdate([Date Closed]), cdate([Date Created]))

    this is done in Access, added a new field then selected Calculated and entered this,... but its not working..

    heres a screen shot showing where the code is at

    http://i.imgur.com/UZZt3k0.jpg


    many thanks in advance

  8. #8
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    threads merged
    please do not start a new thread for the same question.
    I'd rather be riding on the Tiger 800 or the Norton

  9. #9
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    im not sure you can do this as part of a column definition.
    besides which this is derived data that can be calcualted as required in a query or form or report
    I'd rather be riding on the Tiger 800 or the Norton

  10. #10
    Join Date
    Feb 2014
    Posts
    7
    I also put all these codes in the Query Designer....

    same syntax error!

Posting Permissions

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