Home » SQL & PL/SQL » SQL & PL/SQL » sysdate
sysdate [message #201268] Fri, 03 November 2006 06:13 Go to next message
webadministrator
Messages: 45
Registered: October 2005
Member
hello,

if i want to do a query that selects all the companies that are aged less than 1 year, how can this be done? should i use sysdate? i.e select count(*) from company where date_founded < (sysdate - ...)

thank you.
Re: sysdate [message #201269 is a reply to message #201268] Fri, 03 November 2006 06:16 Go to previous messageGo to next message
Littlefoot
Messages: 20891
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
WHERE date_founded > add_months(sysdate, -12)
Re: sysdate [message #201274 is a reply to message #201268] Fri, 03 November 2006 06:26 Go to previous messageGo to next message
webadministrator
Messages: 45
Registered: October 2005
Member
does it work if i want to compare date_founded to another date say: date2.

where date_founded > add_months(date2, -12)

thank you very much.
Re: sysdate [message #201281 is a reply to message #201274] Fri, 03 November 2006 06:40 Go to previous messageGo to next message
amul
Messages: 252
Registered: April 2001
Location: Chennai
Senior Member
of course it will why dont you try it?
Re: sysdate [message #201290 is a reply to message #201281] Fri, 03 November 2006 07:06 Go to previous message
Littlefoot
Messages: 20891
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
SYSDATE is just another date, just like 'date2'. However, perhaps you should pay attention to (possible) difficulties if you rely on currently set NLS_DATE_FORMAT (which might change on another database, or even on this one).

Therefore, don't write something like this
WHERE date_founded > '03.11.2006'
(which, actually, might work at the moment), but rather use TO_DATE function, as
WHERE date_founded > TO_DATE('03.11.2006', 'dd.mm.yyyy')


Previous Topic: query
Next Topic: The "What" parameter in DBMS_JOB.SUBMIT
Goto Forum:
  


Current Time: Sun Dec 04 02:47:01 CST 2016

Total time taken to generate the page: 0.11503 seconds