Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hard coded date...

Status
Not open for further replies.

AJCG

Programmer
Jan 9, 2002
31
GB
Hi All,

Just a quick probably V. Silly question but I would like to hardcode sysdate - 65 years, how do you do this..???

Thanxs

Adam
 
sysdate - 23741 may work

65 * 365.25

I tried to remain child-like, all I acheived was childish.
 
One way to do this is to use the add_months function to subtract 780 months (=12 years) from sysdate. You can truncate the result, if necessary, to get an exact day.

select add_months(sysdate, -780) from dual;
 
If you add a single digit to SYSDATE, you get tomorrow's date. Therefore, I beleive the expression you want is:

"SYSDATE - 23725"

since 365 * 65 = 23725 days.

Hope this helps!
 
The only accurate way is to use add_months. 365 * 65 or even 365.25 * 65 is inaccurate. The actual amount of days per year is in fact 365.2525.
 
I assume that you want to do this to test something like birthday ...
In this case it may be better to do:

to_date(to_char(to_number(to_char(sysdate,'YYYY'))-65)||to_char(sysdate,'MMDD'),'YYYYMMDD')

... this will be a bug on every 29th Feb ... should add a test.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top