Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Compare dates

Re: Compare dates

From: Mark C. Stock <mcstockX_at_Xenquery>
Date: Wed, 7 Jan 2004 07:56:31 -0500
Message-ID: <BPydnVToB9dinGGiRVn-sQ@comcast.com>

<rsj_at_gisportalen.dk> wrote in message
news:bcfec966.0401070446.35e66a2c_at_posting.google.com...
| Hi
|
| I am a newbie to Oracle SQL. I want to know if somebody could help me
| with a problem. I have two tables with a date column. I want to select
| the rows in the first table that have a date >= 4 years than the rows
| in the second table. How do I do that?
|
| Best regards
|
| R

standard oracle date arithmetic is in days so if you're working with weeks, days, hours, minutes, or seconds, can do date addition and subtraction without functions, except for the TRUNC and ROUND functions to change the precision of the date

when comparing dates by months or by years, you need to user the ADD_MONTHS function, which adds a positive or negative number of months to a date

so you'll probably end up with a comparison like this:

    table1.datecol >= add_months(table2.datecol,48)

i.e., table1.datecol is >= the date 4 years after the date in table2.datecol

-- 
Mark C. Stock
mcstock -> enquery(dot)com
www.enquery.com training & consulting
Received on Wed Jan 07 2004 - 06:56:31 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US