Welcome Guest, Not a member yet? Register   Sign In
How to construct mysql query for converting months to years.
#1

[eluser]shankar ganesh[/eluser]
Hello,

Please some one help me how to construct mysql query to convert no of months to years?, please refer the below content how the output should be.

Output should be,

if total months is 36 mnths then output should be 3years.

12mnths -> 1 year
15mnths -> 1 year
18mnths -> 1.5 year
20mnths -> 1.5 year
24mnths -> 2 year
#2

[eluser]regal2157[/eluser]
It would probably be best to use PHP to do the math. Is there a reason you would prefer MySQL to do the work?

A simple /or % would give you the results you expect.

e.g.
Code:
<?php
$months = 36;
echo ($months/12); // would be 3

$months = 18;
echo ($months/12); // would be 1.5

$months = 18;
echo ($months); // would be 6
#3

[eluser]jblack199[/eluser]
regal's answer is correct of course that is of course assuming where the data is coming from.. because you've included no code, you've included no info as to where the # of months is coming from... you will never get a true answer that helps you 100%..

also what have you tried if anything... what have you found via google?

IF by chance the # of months is in a database.. this link might help..

http://stackoverflow.com/questions/19025...by-another
#4

[eluser]shankar ganesh[/eluser]
Hello,

Thanks for your response.




Theme © iAndrew 2016 - Forum software by © MyBB