Gossamer Forum
Home : General : Databases and SQL :

Retrieving date range.

Quote Reply
Retrieving date range.
MYSQL:

I have a column for DATE, by default date is inserted, when the entry is made.

Now I am stuck up, as how to retreive records with a certain range of dates like,

what could be the possible query (if I intent to retrieve records from "2004-03-22" Till "2004-10-30" )

Thanks for any input.

Sara.
Quote Reply
Re: [Sara_Samsara] Retrieving date range. In reply to
Hi,

If it's a DATE column, normal > and < tests work:

SELECT .. FROM .. WHERE datefield > "2004-03-22" AND datefield < "2004-10-30";

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Retrieving date range. In reply to
Sorry to bother you again.

It's not an actual DATE field, I was unable to insert the default DATE in my Script using any functions except for now(), I am using the following query

my $sql =
qq~ INSERT INTO $table(id, job, name, type, chars, trans, tim)
VALUES ('', "$job", "$name", "$type", "$chars", "$trans", now())~;

To trim the time from this field I defined the 'tim' as SMALLINT(10), so it excludes the time and gets only the YYYY-MM-DD.

Please help me either how to insert only the DATE in my script (and I will define the 'tim' as DATE) or a possible different query?

I appreciate your help.

* I am on XP machine.

Sara.