473,411 Members | 1,937 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Query Criteria

54
Is it possible to set criteria for a query that would make it go to the current date except for the hours of midnight to 6am go to the previous date?
Oct 8 '14 #1

✓ answered by twinnyfo

Becker,

If you use:

Expand|Select|Wrap|Line Numbers
  1. Now() - Date()
you will get the decimal part of the Date/Time generated by Now().

The "Time" portion of a date is actually expressed in a decimal in the system. 12:00 Midnight = 0.00000; 12:00 Noon = 0.50000. Thus, the hours between Midnight and 6 Am would be <= 0.25.

So, what you want to evaluate your date/time to be is somewhat similar to this:

Expand|Select|Wrap|Line Numbers
  1. WHERE [Your Date/Time Field] = 
  2.     IIf(Now()-Date()<=0.25,Date()-1,Date())
Hope this hepps!

8 1240
Rabbit
12,516 Expert Mod 8TB
The Date() function will return the current date. The DateAdd() function will let you subtract and add a chosen interval to a date.
Oct 8 '14 #2
Becker
54
Thanks. That helps for finding the previous date. Now how can I specify times to use it at? I want the current date from 6am to midnight and the previous date (using the datadd() function) for midnight to 6am.
Oct 8 '14 #3
twinnyfo
3,653 Expert Mod 2GB
Becker,

If you use:

Expand|Select|Wrap|Line Numbers
  1. Now() - Date()
you will get the decimal part of the Date/Time generated by Now().

The "Time" portion of a date is actually expressed in a decimal in the system. 12:00 Midnight = 0.00000; 12:00 Noon = 0.50000. Thus, the hours between Midnight and 6 Am would be <= 0.25.

So, what you want to evaluate your date/time to be is somewhat similar to this:

Expand|Select|Wrap|Line Numbers
  1. WHERE [Your Date/Time Field] = 
  2.     IIf(Now()-Date()<=0.25,Date()-1,Date())
Hope this hepps!
Oct 8 '14 #4
Becker
54
That works perfectly. Thank you.
Oct 8 '14 #5
twinnyfo
3,653 Expert Mod 2GB
Glad I could help! Let us know if you have additional questions.
Oct 8 '14 #6
NeoPa
32,556 Expert Mod 16PB
Expand|Select|Wrap|Line Numbers
  1. TimeValue(Now())
This is a simpler way of getting to the time-only portion of Now().

Expand|Select|Wrap|Line Numbers
  1. Date() == DateValue(Now())
Thus, the simplest and most straightforward way of returning the date specified would be :
Expand|Select|Wrap|Line Numbers
  1. DateValue(DateAdd("h",-6,Now()))
This reflects going back six hours from the current time and taking the date part of that value.
Oct 9 '14 #7
twinnyfo
3,653 Expert Mod 2GB
NeoPa,

Thank for sharing the two functions above. I didn't know they existed... Now I do!
Oct 13 '14 #8
NeoPa
32,556 Expert Mod 16PB
TwinnyFo:
I didn't know they existed...
You know, I maybe psychic, but I'd guessed that already :-D

Of course you're welcome. Sharing knowledge with those I know will pass it on is always even more pleasing and rewarding.
Oct 14 '14 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: keliie | last post by:
Hello Just a quick question that I've spent a few hours trying to solve with no luck (although one would think this should be fairly easy). I have a form with a subform. The subform is based...
3
by: stevecat | last post by:
Hi there, I have created a form, "search" and a query "search_product". The query returns the product information based upon the criteria for three of the fields, author, title or isbn. The field...
4
waynetheengineer
by: waynetheengineer | last post by:
Hi, I was wondering if anyone had any suggestions on my database: I have a form that accepts user input into a single text box. When the OK button is hit, a query should search for all records...
3
by: ericargent | last post by:
Hi I'm using Acces 2003 I have Query where the several parameters for the criteria are supplied from a form. One parameter source is a combo box. What I am trying to do is if: An item is...
6
craigfr
by: craigfr | last post by:
I am making a graph comparing last year's defect data with YTD defect data. Our fiscal year starts Nov.1 and ends Oct.31. To get the YTD, I started used a simple date serial criteria: Between...
3
by: sfrvn | last post by:
I have searched high and low and cannot find an answer to my problem. So now I turn to the collective genius of this newsgroup. Over-simplified examples This query criteria for field works:...
4
by: tbeers | last post by:
Is there a method to pass along a criteria argument directly to the query criteria rather than through filtering a form or report? In other words, I would like to click a "print" button and in the...
8
by: limperger | last post by:
Hello everyone! First and foremost, my apologies for the title of the post. It is not very clarifying of what the problem is about, but I didn't know how to put it... My problem is as follows: I...
7
by: erichusa86 | last post by:
Hi Basicaly i have a combo box with two options "ug" and "dh". this is the VBA code i have so far: Private Sub cbosample_AfterUpdate() Dim SampleType As String If Me.cbosample = "dh" Then...
7
by: Xenver | last post by:
ok, so i have a form with unbound check boxes on it, i want to alter a query criteria based on the check boxes values,so i have this as an example of my query criteria: IIf(!!=True,>0,Null) SS...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.