Search time

  • Thread starter Thread starter mpaynter
  • Start date Start date
M

mpaynter

I am a new Access designer

What I am trying to do is search a date and time so that I may brin
back results before 12:00

I have 2 columns 1 with the date in and 1 with the time in but canno
get the get the right query I though I should use <= somehow but
can't get my head round it

I am using SQL 2000 as my backend D
 
Dear M Paynter:

I strongly recommend you do not use two separate columns for a date
and time that are closely associated.

Using a datetime or shortdatetime datatype, you can use DatePart to
look at any part of the value: Year, Month, Day, Hour, Minute, or
Second (among others).

DatePart(hh, YourDateAndTime) will give you the hour of the day,
irrespective of what day it is in. Before noon would be when
DatePart(hh, YourDateAndTime) < 12. Is that what you wanted? Your
post said "before 12:00" but it also said "I thought I should use <="
so perhaps you meant before or including noon. That's a little more
difficult:

DatePart(hh, YourDateAndTime) < 12 OR (DatePart(hh, YourDateAndTime) =
12 AND DatePart(n, YourDateAndTime) = 0 AND DatePart(ss,
YourDateAndTime) = 0 AND DatePart(ms, YourDateAndTime) = 0)

Gets a bit more nasty, doesn't it!

Refer to the online help for details.

Note: the "Books Online" for SQL Server comes with "SQL Server
Developer Edition" which is now only $50. This also gives you
Enterprise Manager and Query Analyzer. If you don't have these tools,
I strongly recommend this! (And I don't work for MS, nor do I get a
commission if you buy it. It's just that this stuff is indispensible
if that's what you're working on!) This would make it easy for you to
figure out the solution to your problem, or to study what I've just
shown you in detail.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts
 
Back
Top