View previous topic :: View next topic |
Author |
Message |
anandlall12 Smarty Rookie
Joined: 05 Mar 2014 Posts: 8
|
Posted: Fri Mar 07, 2014 2:04 pm Post subject: how to convert numbers into hour:minutes |
|
|
currently using this string
{math equation="(( x ) / z )" x=$single_array[i].TIME_SPENT z=60}
value of x is 90, this outputs 1.5 which is great, how can I get it to display as 1h:30m ?
Thanks everyone |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Mar 07, 2014 3:05 pm Post subject: |
|
|
Assign the value to a template variable:
{math equation="(( x ) / z )" x=$single_array[i].TIME_SPENT z=60 assign="time"}
Then feed $time into a custom function that takes the number and translates it into a time format. You will need to write that function, or find one that has been written. |
|
Back to top |
|
anandlall12 Smarty Rookie
Joined: 05 Mar 2014 Posts: 8
|
Posted: Fri Mar 07, 2014 10:01 pm Post subject: |
|
|
mohrt wrote: | Assign the value to a template variable:
{math equation="(( x ) / z )" x=$single_array[i].TIME_SPENT z=60 assign="time"}
Then feed $time into a custom function that takes the number and translates it into a time format. You will need to write that function, or find one that has been written. |
Thanks for your reply. I searched the forum but I did not find anything
I also found This online and made a few modifications to it.
{php}
$seconds = 90*60
$hours = floor($seconds / 3600);
$mins = floor(($seconds - ($hours*3600)) / 60);
$secs = floor($seconds % 60);
{/php}
Then I echo using {php}{ echo $hours.'h:'. $mins.'m';}{/php} and it does display the way I want it to. BUT do you know how I can assign {$string} which gets value from MySQL to $seconds = {string /60}
Thanks for the help
Last edited by anandlall12 on Fri Mar 07, 2014 10:05 pm; edited 1 time in total |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
|
Back to top |
|
anandlall12 Smarty Rookie
Joined: 05 Mar 2014 Posts: 8
|
Posted: Fri Mar 07, 2014 10:10 pm Post subject: |
|
|
Those are very similar to the one I have above, and they do work, just that I need it to use values from mysql table rather than a static value. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Mar 07, 2014 10:19 pm Post subject: |
|
|
If you assign your value to the $time template var, you can do this inside the php tags.
$this->getTemplateVars('time')
However, php tags are bad practice, use smarty plugins. see here:
http://www.smarty.net/best_practices |
|
Back to top |
|
anandlall12 Smarty Rookie
Joined: 05 Mar 2014 Posts: 8
|
Posted: Fri Mar 07, 2014 10:38 pm Post subject: |
|
|
mohrt wrote: | If you assign your value to the $time template var, you can do this inside the php tags.
$this->getTemplateVars('time')
However, php tags are bad practice, use smarty plugins. see here:
http://www.smarty.net/best_practices |
I am very new to smarty so that might be an issue for me to code, However I was reading some of the post here and I an thinking of doing something like this
{math equation="(( x ) * z / a )" x=$single_array[i].TIME_SPENT z=60 a=3600} which displays 1.5 as x=90 how can remove the decimal from this string? if I could get that to work then all I have to do is to * the result by 60 and I will get my minutes
Thanks once again |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Mar 07, 2014 11:12 pm Post subject: |
|
|
use round() floor() ceil() in your math equation? |
|
Back to top |
|
anandlall12 Smarty Rookie
Joined: 05 Mar 2014 Posts: 8
|
Posted: Fri Mar 07, 2014 11:23 pm Post subject: |
|
|
mohrt wrote: | use round() floor() ceil() in your math equation? |
I actually used format="%.b" and it removed the decimal and display 1 but having other issues with minutes because I need to take the value from equation 1 and *3600 /60 |
|
Back to top |
|
|