Ken said:
I would always do so myself even
if I'm confident that the date/time values all have zero times of day
Well, you can be 100% confident that no dates have a time element if
you code the rule i.e. by creating a CHECK constraint (or Validation
Rule) e.g.
CREATE TABLE Test (
test_ID INTEGER NOT NULL PRIMARY KEY,
start_date DATETIME DEFAULT DATE() NOT NULL,
CONSTRAINT test_start_date__no_time_element
CHECK(start_date = CDATE(DATEDIFF('d', 0, start_date))),
end_date DATETIME,
CONSTRAINT test_end_date__no_time_element
CHECK(end_date = CDATE(DATEDIFF('d', 0, IIF(end_date IS NULL, DATE(),
end_date))))
);
An attempt to insert a date value with a time element will always fail
e.g.
INSERT INTO Test (test_ID, start_date) VALUES (1, NOW());
Error: "One or more values are prohibited by the validation rule
'test_start_date__no_time_element' set for 'Test'. Enter a value that
the expression for this field can accept."
The presence of a CHECK rule means you can be 100% confident and you
can code accordingly.
[PS to make the above code more friendly to use, create a procedure to
*handle* dates with time elements (i.e. strip time elements before
inserting) e.g.
CREATE PROCEDURE AddTest
test_ID INTEGER,
:start_date DATETIME,
:end_date DATETIME = NULL)
AS
INSERT INTO Test
(test_ID, start_date, end_date)
VALUES
test_ID,
CDATE(DATEDIFF('d', 0, IIF
start_date IS NULL, DATE(), :start_date))),
IIF
end_date IS NULL, NULL, CDATE(DATEDIFF('d', 0, :end_date)))
);
A similar proc may be required to update the table. Now remove
permissions from the base table and grant EXCUTE permissions on the
procs.]
using the following in place of a BETWEEN....AND operation:
WHERE School_Date >= [Enter Start Date:] AND School_Date < [Enter End Date]
+ 1
The drawback of this approach is that you are effectively using two
lines of code to write one search condition. The OP's preference for
the BETWEEN syntax backs the case that it is more intuitive in that it
is more human readable, but the drawback of this is that the data may
not fit the logic. As above, the data can be made to fit by coding the
business rule that end dates will always contain the maximum value for
the time element, which for Jet's DATETIME type is 23:59:59:
CREATE TABLE Test2 (
test_ID INTEGER NOT NULL PRIMARY KEY,
start_date DATETIME DEFAULT DATE() NOT NULL,
CONSTRAINT start_date__no_time_element
CHECK(start_date = CDATE(DATEDIFF('d', 0, start_date))),
end_date DATETIME,
CONSTRAINT end_date__no_time_element
CHECK(end_date = CDATE(DATEDIFF('d', 0, IIF(end_date IS NULL, DATE(),
end_date))) + TIMESERIAL(23, 59, 59))
);
Having coded the rule, the construct
:search_date BETWEEN start_date AND end_date
is intuitive and meaningful.
Jamie.
--