select * from db where DATE = '2002-07-06 ...

Just starting out? Need help? Post your questions and find answers here.
coldarchon
New User
New User
Posts: 4
Joined: Tue Aug 19, 2003 10:34 am

select * from db where DATE = '2002-07-06 ...

Post by coldarchon »

how can I make a query with dates? I have an old Access file with the coloumns Date and Time, and I want to use the Between clause. But I even can´t get a query if I chose a specific date or time. The Date data look like yyyy-mm-dd 00:00:00 and the Time data look like 1899 etc.

I tried wildcards, date with time, just date, date with points, date as a variable, defining date as DATE in SQL, cascading SQL, and whatsoever.

Anyone?
Max.
Enthusiast
Enthusiast
Posts: 225
Joined: Fri Apr 25, 2003 8:39 pm

Re: select * from db where DATE = '2002-07-06 ...

Post by Max. »

coldarchon wrote:how can I make a query with dates? I have an old Access file with the coloumns Date and Time, and I want to use the Between clause. But I even can´t get a query if I chose a specific date or time. The Date data look like yyyy-mm-dd 00:00:00 and the Time data look like 1899 etc.

I tried wildcards, date with time, just date, date with points, date as a variable, defining date as DATE in SQL, cascading SQL, and whatsoever.

Anyone?
You have to use dates like #08/19/2003# (with the leading and trailing #) in Access, if I remember right.
coldarchon
New User
New User
Posts: 4
Joined: Tue Aug 19, 2003 10:34 am

Post by coldarchon »

nope, doesn´t work for me. But the "Like" option works.

Select * From db Where Date Like '06.07.2002'

No Between ...
Max.
Enthusiast
Enthusiast
Posts: 225
Joined: Fri Apr 25, 2003 8:39 pm

Post by Max. »

coldarchon wrote:nope, doesn´t work for me. But the "Like" option works.

Select * From db Where Date Like '06.07.2002'

No Between ...
By using "LIKE '..." you are treating the column as if it was text.

Sorry, if I insist - I probably didn't quite catch you - but given a table "dates" that looks like

Code: Select all

id;datefield
0;30.12.2004 12:00:12
1;22.06.2012 14:00:01
2;08.08.1972 08:10:01
3;19.01.2002 07:03:00
an example query would be

Code: Select all

SELECT datefield FROM dates WHERE datefield>#1/1/1975# AND datefield<#1/1/2006#;
and return 2 rows of data:

Code: Select all

30.12.2004 12:00:12
19.01.2002 07:03:00
If this doesn't work, the column of the Access DB probably isn't formatted as Date/Time for whatever reason!?

And sorry for picking such lousy dates... :P
coldarchon
New User
New User
Posts: 4
Joined: Tue Aug 19, 2003 10:34 am

Post by coldarchon »

hey, thanks for the help, I used the "Like"-option, it was too confusing. The date was like dd.mm.yyyy , the ODBC returns it like yyyy-mm-dd when I make a request like #mm/dd/yyyy# .

But now I´m stuck on creating an output into an *.xls sheet. How can I use the cell C3 (3, 3)?
Post Reply