Jannat Pia
Jannat Pia

Reputation: 39

How to convert sec to min, hour, day, week?

I have a seconds variable. How to convert its content to hours, days and weeks?

{assign var="formin" value="{$sec/60}"}

{$formin}

Upvotes: 0

Views: 68

Answers (1)

Deykun
Deykun

Reputation: 1271

You should use date object with date_format (ex. {$smarty.now|date_format:"%D"}) because you can use conversion specifiers with it. More about that here: https://www.smarty.net/docsv2/en/language.modifier.date.format.tpl

If you still want to convert seconds to weeks in your template you can put calculations in smarty brackets:

{$sec/60}
{$sec/(60*60*24)}
{$sec/(60*60*24*7)}

Optionaly you can use string_format to round it up (ex. {$sec/(60*60*24*7)|string_format:"%d"}): https://www.smarty.net/docsv2/en/language.modifier.string.format.tpl

Upvotes: 1

Related Questions