Query dates saved as text... (1 Viewer)

tangcla

Registered User.
Local time
Today, 17:12
Joined
Sep 8, 2008
Messages
35
In a continuation of this thread here, I have a table which has a date/time field which contains a timestamp (which I can omit, if someone can tell me how to do so with a linked table...)

I want to do date-based queries with this, i.e. between Now() and Now()-28, but because it's a text field, this does not work.

Is there a way to treat the column as a date field for the purpose of the query?
 

giovaanni

Registered User.
Local time
Today, 00:12
Joined
Feb 19, 2009
Messages
27
Just do a CDATE(yourdatefield) and then filter this by your range.
 

tangcla

Registered User.
Local time
Today, 17:12
Joined
Sep 8, 2008
Messages
35
Just do a CDATE(yourdatefield) and then filter this by your range.
Do I do this inline or does it have to be run to convert a table column first?
 

giovaanni

Registered User.
Local time
Today, 00:12
Joined
Feb 19, 2009
Messages
27
Just type what I mentioned into a field in a query that has your date field.
 

giovaanni

Registered User.
Local time
Today, 00:12
Joined
Feb 19, 2009
Messages
27
It doesn't have to be converted first, you can have the expression field on it's own and then filter it by typing into the criteria between now() -25 and now() for the field.
 

tangcla

Registered User.
Local time
Today, 17:12
Joined
Sep 8, 2008
Messages
35
It doesn't have to be converted first, you can have the expression field on it's own and then filter it by typing into the criteria between now() -25 and now() for the field.
It won't work that way, it will treat it as between Now() and Now()-"28" automatically.
 

giovaanni

Registered User.
Local time
Today, 00:12
Joined
Feb 19, 2009
Messages
27
That means you have nulls in your date text column.

In that case do this CDATE(NZ(yourdate,0)) for the expression field in the query.
 

tangcla

Registered User.
Local time
Today, 17:12
Joined
Sep 8, 2008
Messages
35
That's the strange thing - there are no blanks in the dataset, I tried.

As another approach, I used the DateValue() function and that allowed me to convert the text to date - however I think because Access thinks that the field is text, it won't allow me to use date functions to specify query criteria.
 

Users who are viewing this thread

Top Bottom