View previous topic :: View next topic |
Author |
Message |
omexlu Smarty Rookie
Joined: 13 Mar 2014 Posts: 27
|
Posted: Sat May 05, 2018 3:12 am Post subject: Smarty: Time-Modifications |
|
|
Hello,
I have a variabel {$getRow.date} (comes from a foreach loop) who contains a mysql datestamp and a second variable {$getRow.time} who contrains a string (example: 11 [min.]).
How can i now subract '11 minutes' from the first variable and get the new timestamp that i can formate with date_format?
PS. Sorry for my bad english i hope you understand me
Thanks in advance. |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Sat May 05, 2018 6:48 am Post subject: |
|
|
You can try:
Code: | {"`$getRow.date` -`$getRow.time`"|strtotime|date_format:"%c"} |
You will need to make sure the 'time' string is understandable to PHP.
I think "11 [min]" is not understandable, but "11 minutes" is understandable.
Everything starts as a string, but embedded Smarty variables are escaped with backticks. |
|
Back to top |
|
omexlu Smarty Rookie
Joined: 13 Mar 2014 Posts: 27
|
Posted: Sat May 05, 2018 9:25 am Post subject: |
|
|
Hello,
Thanks for you reply.
$getRow.time CONTAINS ONLY a number = 11
Maybe somthing like that is possible?:
Code: | {"`$getRow.date` -`$getRow.time` minutes"|strtotime|date_format:"%c"} |
I will give it a try this evening or tomorrow. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sat May 05, 2018 1:17 pm Post subject: |
|
|
Write a wrapper function that uses DateTime and DateInterval classes to manipulate times.
omexlu wrote: | Maybe somthing like that is possible?:
Code: | {"`$getRow.date` -`$getRow.time` minutes"|strtotime|date_format:"%c"} |
|
It is possible, but very dirty and prone to failures.. |
|
Back to top |
|
omexlu Smarty Rookie
Joined: 13 Mar 2014 Posts: 27
|
Posted: Sat May 05, 2018 1:32 pm Post subject: |
|
|
Hi,
After some testings i think i have found a better way to do this with math function:
Code: | {math equation="a - (60 * b)" a=$getRow.date|strtotime b="10" assign="finalTime"}{$finalTime|date_format:"%H:%M"} |
Here i get the correct results of that row -10 minutes.
What do you think about?
EDIT: After do the script all works like a charm |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sat May 05, 2018 9:24 pm Post subject: |
|
|
I already said what I think about it. Dirty hack built on presumptions. |
|
Back to top |
|
scuzzy Smarty Regular
Joined: 31 Aug 2003 Posts: 84
|
|
Back to top |
|
|