Results 1 to 4 of 4
  1. #1
    Join Date
    May 2012
    Posts
    7

    Red face Unanswered: Date/Time Query Help

    Hi
    wondering if you can help me.
    I'm looking to extract records in a query that are between 4pm yesterday and 4pm today and i'm struggling with getting the between times bit.

    Thanks

  2. #2
    Join Date
    Dec 2010
    Location
    Manchester
    Posts
    24
    do you intend to put these records into a report or somewhere else in the data base or extract them outside the database?
    Code:
    If Me.OpenAccess.Work Then
    Access.Crash = Inevitable
    End If
    Me.BangHeadAgainstWall = Headache

    I dont need you to solve my problem, just give me a push in the right direction.

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    its all down to the where clause
    using the correct datetime function and the between operator

    Code:
    where adatecolumn between dateadd("h",-8,date()) and dateadd("h",+16,date())
    the between operator acts as a banding constraint, the only wrinkle is that the the values must be in ascendign order ie between lowervalue and uppervalue
    the dateadd function requires you to specify the type of datetime addition you want to do 'h' is hours, the amount to change and the value to apply the change to. in this case thats -8 or +16 to give 16:00 and date() returns the current system date
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    May 2012
    Posts
    7
    thanks guys, perfect

Tags for this Thread

Posting Permissions

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