Access Query with Time function


In my query, I'm trying to put this in the criteria but getting errors with my syntax.  No matter the date, I'm just trying to set a time range.

TimeValue([WhateverDate]) > 4:30 PM and TimeValue([WhateverDate]) < 12:00 AM

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

omgangIT ManagerCommented:
Dates/times in Access are indicated with # symbols.


 TimeValue([WhateverDate]) > #4:30 PM# and TimeValue([WhateverDate]) < #12:00 AM#

OM Gang
Genius123Author Commented:
With that, I'm getting a Data type mismatch error.  But I know my [WhateverDate] field is a DateTime field, so I'm not sure why I'm getting the error....
Randy PooleCommented:
I assume your whateverdate is not  a field name so:
 TimeValue(#2015-10-02 05:30:00 PM#) > #4:30 PM# and TimeValue(#2015-10-02 10:00:00 PM#) < #12:00 AM#

Open in new window

I don't think you are using TimeValue correctly

It's looking for a string to return as a DateTime -- and you are giving it a DateTime
Hence the mismatch.

DateTimes are a special form of Double
So you are looking to get rid of the integer part of that Double
(Day Zero is 30-Dec-1899, times are the fraction of the day.  So 5-Oct-2015 12:00 PM is 42282.5 as a double.  Discard the 42282, and keep the fraction, and coerce it back to DateTime.) and then compare.

CDate(CDbl([WhateverDate]) - Round(CDbl([WhateverDate]),0)) > #4:30 PM# and CDate(CDbl([WhateverDate]) - Round(CDbl([WhateverDate]),0))<#11:59:59.9999 PM

The bold expression is going to return a Boolean -- so I assume there's more to your code line than what you posted.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Genius123Author Commented:
That worked, thank you very much.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.