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
 Convert a decimcal to years and month

Author  Topic 

h2sut
Starting Member

40 Posts

Posted - 2010-05-05 : 23:03:50
I have a question is there a way i can convert 17.5 to be 17 years and 6 months? Not sure if there a way to do it

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-05-05 : 23:46:10
If this is for presentation then i suggest you do it in front end..


Regards,
Bohra

I am here to learn from Masters and help new bees in learning.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-05-06 : 13:14:58
just do like


SELECT FLOOR(number) AS years,number-FLOOR(number) * 12 AS months
FROM Table


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

Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2010-05-06 : 13:23:20
[code]SELECT FLOOR(17.5) AS years,(17.5-FLOOR(17.5)) * 12 AS months [/code]

http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-05-06 : 13:41:59
well is .5 year really 6 months?

SELECT 365*.500




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

h2sut
Starting Member

40 Posts

Posted - 2010-05-07 : 16:25:44
I really appreciate the help. This worked. I was trying to % and getting issues. Thanks again for your help.

quote:
Originally posted by visakh16

just do like


SELECT FLOOR(number) AS years,number-FLOOR(number) * 12 AS months
FROM Table


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



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-05-08 : 06:04:38
welcome

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

Go to Top of Page

Tks
Starting Member

48 Posts

Posted - 2010-05-08 : 08:56:48
I would convert the field in de table to datetime. In every language there is a way to calculate the difference and store it as a datetime.
In that way you can just do select year(datetimecolumn) as Years, month(datetimecolumns) as months etc...

Go to Top of Page
   

- Advertisement -