Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Date calculation

Author  Topic 

nuruddean
Starting Member

11 Posts

Posted - 2010-05-05 : 02:51:20
I choose to retire on my 58 age.

My date of birth is 10/03/1980

I use this script:
sysdate + ((58 - round((sysdate - a.date_of_birth)/365,2)) * 365 )

the output is 02/25/2038

the year is correct but the date is incorrect, it should be 03/10/2038

please help me on this matter


My Name is Nuruddin

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-05-05 : 02:52:24
select dateadd(yy,58,'19801003')



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-05-05 : 02:55:43
are you using sql server? sysdate is not in sql server

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-05-05 : 02:56:31
quote:
Originally posted by nuruddean

I choose to retire on my 58 age.

My date of birth is 10/03/1980

I use this script:
sysdate + ((58 - round((sysdate - a.date_of_birth)/365,2)) * 365 )

the output is 02/25/2038

the year is correct but the date is incorrect, it should be 03/10/2038

please help me on this matter


My Name is Nuruddin


First question is 10/03/1980 is 10th march or 3rd October ?
and second one are you using SQL Server?

Vaibhav T

To walk FAST walk ALONE
To walk FAR walk TOGETHER
Go to Top of Page

nuruddean
Starting Member

11 Posts

Posted - 2010-05-05 : 03:07:13
1) i'm using oracle
2)10th march

My Name is Nuruddin
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-05-05 : 03:16:03
http://www.databasejournal.com/scripts/article.php/3762331/DateAdd-function-Oracle.htm


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

nuruddean
Starting Member

11 Posts

Posted - 2010-05-05 : 04:23:30
ok i found it from other site... i use add_month thank you...

My Name is Nuruddin
Go to Top of Page
   

- Advertisement -