I am trying to pull a query for times greater than 5am...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sooli
    New Member
    • Sep 2014
    • 49

    I am trying to pull a query for times greater than 5am...

    for some reason when i pull my query with the following parameters...


    Date field (formatted to short date)
    Code:
    >[Enter yesterdays date]

    Time field (formatted to short time)


    Code:
    >Hour(5)
    i still get everything ever inputted for the day. Is there some trick to making access see the time and to only display the times i tell it to?

    What i really need it to do is pull all data that is greater than yesterday at 5:00 am...

    and in-case you were wondering, I also tried > #05:00:00 am# and that doesn't work either.
    Last edited by sooli; Dec 24 '14, 11:07 AM. Reason: added explanation
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3664

    #2
    sooli,

    Try to keep in mind that Dates are integers and times are fractions of integers. So, 5:00 am is actually 0.208333.

    To calculate times, the best method is to use the DateAdd() Function. So, to determine a date at 5:00 am, you would take the date (be sure to use a DATE and not a DateTime) and add 5 hours:

    Code:
    WHERE [DateTimeField] > #" & _
        DataAdd("h", 5, [Enter yesterdays date]) & "#"
    This works, because "yesterday' s date" is, technically speaking, 12/23/2014.0000. When you add 5 hours, that new, numerical value becomes 12/23/2014.208333.

    Hope this hepps!

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      Also, if the parameter is always yesterday's date, there's no need to prompt for it. You can subtract one day from the current date.

      By the way, just because you're not displaying the date portion doesn't mean it's not there in the data. #5:00 AM# has a hidden date portion of 12/30/1899.

      And Hour(5) is getting the hour of the value #01/04/1900 00:00:00 AM# which is equal to 0.
      Last edited by Rabbit; Dec 24 '14, 04:48 PM.

      Comment

      • sooli
        New Member
        • Sep 2014
        • 49

        #4
        THANK YOU! This worked perfectly! You rock!

        Comment

        • sooli
          New Member
          • Sep 2014
          • 49

          #5
          Thank you for the excellent explanation! Now this makes sense!

          Comment

          • sooli
            New Member
            • Sep 2014
            • 49

            #6
            well.. something has gone wrong.. its not working... it is still pulling the whole day's data... not just from yesterday @ 5:00 am to today @ 5:00 am...

            here's my code:
            Code:
            SELECT MonitoringCheck.Solution, MonitoringCheck.CDate, MonitoringCheck.CTime, MonitoringCheck.Technician, MonitoringCheck.MonitoringComplete, MonitoringCheck.Incident, MonitoringCheck.Server, MonitoringCheck.Comments, MonitoringCheck.LogFile, MonitoringCheck.ProductionVerification, MonitoringCheck.TestVerification, MonitoringCheck.MIPPatchingVerification, MonitoringCheck.MIPPatchingVerification, MonitoringCheck.CAECoreCopied, MonitoringCheck.MachineAddCreation, MonitoringCheck.MachineAddResolution, MonitoringCheck.MachineDesubCreation, MonitoringCheck.MachineDesubResolution, MonitoringCheck.[SEPHomeUse(NoNew)], MonitoringCheck.[SEPHomeUse(Posted)]
            FROM MonitoringCheck
            WHERE (((MonitoringCheck.CDate)>=DateAdd("h",0.5,[enter yesterdays date])))
            ORDER BY MonitoringCheck.CDate, MonitoringCheck.CTime;
            Last edited by sooli; Dec 29 '14, 11:24 AM. Reason: fixing code

            Comment

            • sooli
              New Member
              • Sep 2014
              • 49

              #7
              I think i got it! using the .20833
              Code:
              SELECT MonitoringCheck.Solution, MonitoringCheck.CDate, MonitoringCheck.CTime, MonitoringCheck.Technician, MonitoringCheck.MonitoringComplete, MonitoringCheck.Incident, MonitoringCheck.Server, MonitoringCheck.Comments, MonitoringCheck.LogFile, MonitoringCheck.ProductionVerification, MonitoringCheck.TestVerification, MonitoringCheck.MIPPatchingVerification, MonitoringCheck.MIPPatchingVerification, MonitoringCheck.CAECoreCopied, MonitoringCheck.MachineAddCreation, MonitoringCheck.MachineAddResolution, MonitoringCheck.MachineDesubCreation, MonitoringCheck.MachineDesubResolution, MonitoringCheck.[SEPHomeUse(NoNew)], MonitoringCheck.[SEPHomeUse(Posted)]
              FROM MonitoringCheck
              WHERE (((MonitoringCheck.CDate)>Date()-2) AND ((MonitoringCheck.CTime)>0.20833))
              ORDER BY MonitoringCheck.CDate, MonitoringCheck.CTime;
              seems to be working

              Comment

              • sooli
                New Member
                • Sep 2014
                • 49

                #8
                nope... i'm at a loss... the last bit of code was eliminating the some of the data before 5am on the current day.. i don't get it...

                Comment

                • twinnyfo
                  Recognized Expert Moderator Specialist
                  • Nov 2011
                  • 3664

                  #9
                  I would still recommend going with your code in Post #6, but change line 3:

                  Code:
                  WHERE (((MonitoringCheck.CDate)>=DateAdd("h",5,[enter yesterdays date])))
                  Your code was looking at all times after 12:30 am.

                  Comment

                  • Rabbit
                    Recognized Expert MVP
                    • Jan 2007
                    • 12517

                    #10
                    You didn't mention this before:
                    ... to today @ 5:00 am...
                    You need an additional filter to account for this.

                    Comment

                    • sooli
                      New Member
                      • Sep 2014
                      • 49

                      #11
                      so something like:
                      Code:
                       Where monitoringcheck.CDate  BETWEEN(((monitoringcheck.CDate)>=DateAdd("h",5,[enter yesterdays date] AND((monitoringcheck.CDate)<=DateAdd("h",5,date()))
                      im not at work to try... but thought I'd run this by you all while it was on my mind...

                      Comment

                      • sooli
                        New Member
                        • Sep 2014
                        • 49

                        #12
                        well that didn't work either... still pulling from midnight rather than 5:00 am....

                        on another note... if I can...

                        how in the world do i hide the database window? The thing takes up the whole screen, all my users need are the forms I created... used to be a check box that would let you not display the application... that feature seems to be gone in 2013 =/

                        Comment

                        • twinnyfo
                          Recognized Expert Moderator Specialist
                          • Nov 2011
                          • 3664

                          #13
                          First, are you SURE that monitoringcheck .CDate is a Date/Time?

                          If it is, then try this:

                          Code:
                          WHERE monitoringcheck.CDate BETWEEN DateAdd("h",5,DateAdd("d", -1, Date()) AND DateAdd("h", 5, Date())
                          Try that.

                          As far as your second question in the last post, please start a new thread, and I'd be glad to provide the solution I use (we like to avoid multiple questions in one thread).

                          Comment

                          • sooli
                            New Member
                            • Sep 2014
                            • 49

                            #14
                            Yes, it is definatly a date/time in the table, set to short date format, and the CTime is also a date/time format in the table, set to short time format.

                            Dates and times are auto populated on a click event
                            Last edited by sooli; Dec 30 '14, 02:57 PM. Reason: explanation

                            Comment

                            • twinnyfo
                              Recognized Expert Moderator Specialist
                              • Nov 2011
                              • 3664

                              #15
                              When you assign the Date/Time in the OnClick event are you using Date() or Now()?

                              Comment

                              Working...