Richard Korts
asked on
Access Query
See attached.
I want to make this DateEntered > 12/31/2010 and DateEntered < 01/01/2013.
In other words the years 2011 & 2012.
How do I do that?
Thanks
Access-Query.jpg
I want to make this DateEntered > 12/31/2010 and DateEntered < 01/01/2013.
In other words the years 2011 & 2012.
How do I do that?
Thanks
Access-Query.jpg
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Be careful. Depending on the field type (If it's a datetime field as opposed to a date field) then 12/31/2010 is at midnight and would include all items with that date. If you want 2011 and 2012 only then (again, if it's a datetime field) you want to specify:
> #01/01/2011# and < #01/01/2013#
> #01/01/2011# and < #01/01/2013#
The fun thing to be aware of is that Access ALWAYS stores a date and time.
I suspect you're after All items >= 1/1/2010 and <=1/1/2013
The bad things happen when you mix storing a datetime with Now() (which adds a time) and Date() or programmatically -- which doesn't
The BETWEEN keyword works -- but remember the time!
Between #12/31/2010 11:59:59 PM# AND #01/01/2013#
will get you all items between 1-Jan-2010 and 1-Jan-2013 12:00:00 AM
Which would include all those items where no time was specified on 1-Jan-2013
Between #01/01/2013# and Now() would again get all those no-time-specified items from 1-Jan-2013
Specify the time in your criteria and you'll ALWAYS get what you want, using >= <= or between
I suspect you're after All items >= 1/1/2010 and <=1/1/2013
The bad things happen when you mix storing a datetime with Now() (which adds a time) and Date() or programmatically -- which doesn't
The BETWEEN keyword works -- but remember the time!
Between #12/31/2010 11:59:59 PM# AND #01/01/2013#
will get you all items between 1-Jan-2010 and 1-Jan-2013 12:00:00 AM
Which would include all those items where no time was specified on 1-Jan-2013
Between #01/01/2013# and Now() would again get all those no-time-specified items from 1-Jan-2013
Specify the time in your criteria and you'll ALWAYS get what you want, using >= <= or between
DateTimes are always a pain until you understand how Access handles them.
They are ALWAYS stored as a special kind of Double.
The decimal part is always positive, denoting the fraction of the day
0.0 is midnight
0.333333 is 8 AM
0.5 is 12 PM
0.666666 is 8 PM
0.99999999999999 (however far) is 11:59:59.999999 (however far) PM
Zero day is 30-Dec-1899
Today is day 41974, and the time (in MDT 5:39 PM) is .7356944444
If you create a field with a datetime and a format of "dd-mmm-yy" and dump NOW() into it,
What you'll actually put into it is 41974.7356944444
If put 5:40:00 PM in there, what actually goes is 0.7356944444
if you pull that back out and format it with "dd-mm-yyyy hh:mm:ss AM/PM",
you'll get 30-Dec-1899 05:40:00 PM
Ulitmately, everything gets knock into Doubles for comparison --including criteria. Leave no ambiguity by making one half of a BETWEEN .9999999 and the other .0000000 and you're off and running
They are ALWAYS stored as a special kind of Double.
The decimal part is always positive, denoting the fraction of the day
0.0 is midnight
0.333333 is 8 AM
0.5 is 12 PM
0.666666 is 8 PM
0.99999999999999 (however far) is 11:59:59.999999 (however far) PM
Zero day is 30-Dec-1899
Today is day 41974, and the time (in MDT 5:39 PM) is .7356944444
If you create a field with a datetime and a format of "dd-mmm-yy" and dump NOW() into it,
What you'll actually put into it is 41974.7356944444
If put 5:40:00 PM in there, what actually goes is 0.7356944444
if you pull that back out and format it with "dd-mm-yyyy hh:mm:ss AM/PM",
you'll get 30-Dec-1899 05:40:00 PM
Ulitmately, everything gets knock into Doubles for comparison --including criteria. Leave no ambiguity by making one half of a BETWEEN .9999999 and the other .0000000 and you're off and running
ASKER
I selected the first offered solution, it seems to have worked.
The odds are GREAT there are no items in the table entered on New Years Eve or New Years Day anyway; I know that based on the context.
The odds are GREAT there are no items in the table entered on New Years Eve or New Years Day anyway; I know that based on the context.
:)
Likely to be so.
Our fiscal year runs Mar 1 to the last day of February, so you get those times when the padding isn't there.
Then it's good to know how it all works.
A lot of folks get confused because dates are most definitely NOT WYSIWYG.
How you format a date has absolutely nothing to do with its actual value.
Glad to have been of service
Nick67
Likely to be so.
Our fiscal year runs Mar 1 to the last day of February, so you get those times when the padding isn't there.
Then it's good to know how it all works.
A lot of folks get confused because dates are most definitely NOT WYSIWYG.
How you format a date has absolutely nothing to do with its actual value.
Glad to have been of service
Nick67
BETWEEN #1/1/2011# and #31/12/2012#
Or add another column with the 'display' checkbox unchecked
Year(DateEntered)
with criteria
in(2011,2012)
A few ways to skin this particular cat, though Nick's way is as good as any :)