Date comparison puzzle

FuzMic

DataBase Tinker
Local time
Today, 13:04
Joined
Sep 13, 2006
Messages
744
Hi

I try to select from table records where a date.fld eg DTrn is > (date() - 12). I tried varying it with format(dd-mmm-yy) & ## (on the field and the variable) but can't get it fix.

Please help.
 
PS:
Just got it fixed using

Format([DTrn], 'dd-mmm-yy') > Format((Date() - 3),'dd-mmm-yy');

Resolved
 
What are the symptoms of the problem? How did it fail?
 
PS:
Just got it fixed using

Format([DTrn], 'dd-mmm-yy') > Format((Date() - 3),'dd-mmm-yy');

Resolved

That might work accidentally on some dates but could not possibly be reliable.

By using Format you are comparing on the alphabetical order of the dates as strings.
 
Galaxiom, you seem to say you have a better way, how?
MarkK, if just failed to select.
Thanks.
 
Is the date field you are testing definitely a Date/Time field type in the table, not text?
 
It is a date type field being tested.
 
This condition on the field should show all records with dates within the past 12 days or in the future.

Code:
> Date() - 12

Something odd going on. Is the query just in the Query Designer against a linked or local table in Access? Not built as SQL in VBA?

Can you post the cut down database?
 
Hi mate

It is a linked table in the FE. It is actually a new ADODB.recordset in a VBA script that failed to pick up correctly.

rs.Open "SELECT Sum(Amt) AS SAmt FROM Trn WHERE [TDate] > Date() - 3;", _
CurrentProject.Connection, 1, 3, 1

Hope this will give you a clue instead of a cut.down .mdb. All these happening in access.03 in win10.64bit OS.
 

Users who are viewing this thread

Back
Top Bottom