Text field containing date to query within date range

G

Guest

I am running a query on a database I cannot modify.
A Text Field contains a string with a date format of "mm/dd/yy"
I need to display all records within a date range. The minimum and maximum
dates of the date range are also strings.
I've tried BETWEEN with no success.

Any and all suggestions are very much appreciated.
 
M

Marshall Barton

Kenz21 said:
I am running a query on a database I cannot modify.
A Text Field contains a string with a date format of "mm/dd/yy"
I need to display all records within a date range. The minimum and maximum
dates of the date range are also strings.
I've tried BETWEEN with no success.



Convert the strings to date values:

CDate(datefield) Between [start date AND [end date]
 
G

Guest

Thanks for replying Marshall,

I tried what you recommended and I get the following error message ...
"Invalid use of Null"

Marshall Barton said:
Kenz21 said:
I am running a query on a database I cannot modify.
A Text Field contains a string with a date format of "mm/dd/yy"
I need to display all records within a date range. The minimum and maximum
dates of the date range are also strings.
I've tried BETWEEN with no success.



Convert the strings to date values:

CDate(datefield) Between [start date AND [end date]
 
M

Marshall Barton

So, some records have a Null value in the "date" field?

Try this:

CDate(Nz(datefield,"1/1/3333") Between [start date] AND [end
date]
 
G

Guest

Thanks again Marshall,

I forgot to mention that I am accessing this DB from an ASP .Net webpage.
It did not allow me to use the Nz( ), so I found the following to work:

"SELECT * FROM Project WHERE
IIf(IsNull(Project.Date),0,CDate([Project.Date])) BETWEEN #" +
ddlBeginDate.SelectedItem.Text + "# AND #" + ddlEndDate.SelectedItem.Text +
"#"

Again,
Thanks for pointing me in the correct direction.

Marshall Barton said:
So, some records have a Null value in the "date" field?

Try this:

CDate(Nz(datefield,"1/1/3333") Between [start date] AND [end
date]


I tried what you recommended and I get the following error message ...
"Invalid use of Null"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

query on date 1
Date comparison 2
Date Range 3
Create Date Field from Text 2
Date Range 1
QUERY DATE RANGE 4
Date/time query 1
Formatting date gives bad results in query 2

Top