Re: counting days in a query
From: Bjorn Abelli (DoNotSpam.bjorn_abelli_at_hotmail.com)
Date: 12/26/03
- Previous message: Ike: "counting days in a query"
- In reply to: Ike: "counting days in a query"
- Next in thread: Lee Fesperman: "Re: counting days in a query"
- Reply: Lee Fesperman: "Re: counting days in a query"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 26 Dec 2003 22:00:04 +0100
"Ike" wrote...
> How can I make a query such that in the "WHERE" part
> of my clause, I want to put something to the effect
> that, say, X days have elapsed since a given date.
This is not a Java-related question, and you should try to ask such
questions in a database-specific group.
> For example, suppose in my table, I have a boolean
> field and a date field. I want to create a query
> asking for those rows where X days have elapsed
> from the date field in a row and the boolean, say, is false.
Most databases has built-in-functions to compare dates, but in most cases
they are database-specific. When you ask such questions, please also make a
note on which database you're using. If the database conforms to SQL99, I
don't even think that you need special date-functions.
> Do I need to create a third field, called, say "X"
> for how many days have elapsed between the date field
> and today, and update every row in the table
> every day?
No, this should in most cases not be necessary, but you'll have to look up
in the documentation for the specific database how the Date- and
Boolean-types are implemented, and which functions you need for the query.
Just an example, not db-specific and probably wrong for most databases:
SELECT *
FROM myTable
WHERE (CURRENT_DATE - myDateField) >= 10
AND myBooleanField = TRUE;
// Bjorn A
- Previous message: Ike: "counting days in a query"
- In reply to: Ike: "counting days in a query"
- Next in thread: Lee Fesperman: "Re: counting days in a query"
- Reply: Lee Fesperman: "Re: counting days in a query"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|