Results 1 to 8 of 8
  1. #1
    edmscan is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    168

    DateAdd issue


    I am trying to retrieve records for the past 24 hours .. from a table. I have 2 DateTime fields .. named TransDate and TransTime containing for example 2014/09/25 and 12:45:45 PM respectively.
    (I know they are not stored this way ... )

    However .. because they are in separate fields .. I cannot find how to make this happen. If they are in one field in the table .. ie 2014/09/25 12:45:45 PM then I can use DateAdd as below and it works fine.
    I can use criteria of .. DateAdd("s",-86400,Now()) .. and I get the 2 records I expect.

    I do not want to combine them into one field in the table .. as that just complicates things elsewhere, and there are over 4 million records in the table .. and I want to keep the table as small as possible

    I am using this in a query .. and need a criteria that will work. The below does not work ...

    Select * from Transmissions Where TransDate > DateAdd("s",-86400,Now()) And TransTime > DateAdd("s", -86400,Now());

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Maybe:

    WHERE TransDate + TransTime > DateAdd("s", -86400, Now())
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    edmscan is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    168
    Ok .. tried it. I get no results.

    Also .. tried putting CDate in there .. and same thing.

  4. #4
    edmscan is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    168
    Well .. I found my solution. I combined the 2 fields .. and interestingly it did not increase the size of the file at all. So .. I have my solution. The query will work just fine when the fields are combined .. but if
    you have a thought on how to do it with 2 fields I would be interested in hearing about it.

    Thanks June7.

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You could combine the fields in the query....

    Query1 is the data set - no criteria
    Query2 is the data set - with criteria

  6. #6
    edmscan is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    168
    Thanks ssanfu .. that works perfectly.

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    you have a thought on how to do it with 2 fields I would be interested in hearing about it.
    Do you mean like Query3?

    I think 84600 seconds = 1440 minutes = 1 day, so you can use > DateAdd("s", -86400, Now()) for the criteria for TransDate.
    Then have to limit TransTime. You are using Now(), so get the current time as the criteria for TransTime.

    Maybe??

  8. #8
    edmscan is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    168
    Either query 2 or 3 seem to work just fine with 2 fields. And .. my results are returned pretty fast. I am going to work on optimizing the 4 queries I did today.

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

Similar Threads

  1. DateAdd DateSerial
    By aellistechsupport in forum Queries
    Replies: 2
    Last Post: 04-30-2014, 05:09 PM
  2. the DateAdd
    By azhar2006 in forum Queries
    Replies: 1
    Last Post: 04-20-2014, 03:18 PM
  3. DateAdd()
    By cbrsix in forum Programming
    Replies: 3
    Last Post: 11-22-2011, 02:20 PM
  4. dateadd help
    By dubsdj in forum Queries
    Replies: 3
    Last Post: 03-03-2011, 07:22 PM
  5. Help Please - DateAdd Function
    By graviz in forum Queries
    Replies: 3
    Last Post: 03-02-2010, 02:34 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