Results 1 to 8 of 8
  1. #1
    MFS is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2009
    Location
    Ohio
    Posts
    235

    Only show data in query from present time to 2 hours prior.

    Hello all,
    I've been working on my database pretty hard over the last few days and asking for a lot of help on this forum. One thing I found out is that sending 'time' to the DB in a text format can mess a huge amount of stuff up when trying to query a time field. So recently I had someone help me with
    Code:
    ConvertedTime: CDate([Time1])
    However, Now all my old code that June7 and others have helped me with does not work, so yes, I'm somewhat starting over with my query design.

    What I'm asking for in this thread is support writing code in my query criteria to only show data for the past two hours from the present time. (No matter what time I open the Query. Only show past two hours of data from that time)



    Mike

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    Use Google with these terms.

    1) techonthenet Access now
    2) techonthenet Access DateAdd

    These will show you the purpose and syntax with examples.

    Something like this (substitute your fields and table name as appropriate)

    Select yourdata from yourTable
    Where ConvertedTime Between Now and DateAdd("h", -2, Now)

  3. #3
    MFS is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2009
    Location
    Ohio
    Posts
    235
    orange,
    Yes I've tried, Between Now and DateAdd("h", -2, Now), and I get a message box stating "Invalid use of Null".

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Do you have any Null entries in your ConvertedTime field?

  5. #5
    MFS is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2009
    Location
    Ohio
    Posts
    235
    Yes, I do.
    I'll look in my table and add a time or if they are not required I'll delete them, and then get back with you

  6. #6
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    the syntax is, the dateadd syntax looks right. the now() is a function call.

    Between Now() and DateAdd("h", -2, Now())

  7. #7
    MFS is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2009
    Location
    Ohio
    Posts
    235
    My solution to this problem.
    My tables are now not allowed to have NULL values in the Date and Time Fields.
    So far everything is looking good.
    Thanks To All For The Support

  8. #8
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Your welcome.
    Sounds like a good plan!

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

Similar Threads

  1. Only show data for past 4 hours
    By MFS in forum Queries
    Replies: 7
    Last Post: 02-28-2014, 02:45 PM
  2. Replies: 1
    Last Post: 01-10-2014, 09:51 AM
  3. Replies: 4
    Last Post: 08-06-2012, 10:25 AM
  4. Calculation for time x hours in table
    By hellojosie in forum Access
    Replies: 6
    Last Post: 11-20-2011, 01:54 AM
  5. present date in data field
    By johnkl49 in forum Access
    Replies: 2
    Last Post: 09-14-2009, 04:18 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