Page 1 of 1
Hi, i am searching for a date format in Gallerz
Posted: Sun Mar 18, 2018 7:28 pm
by janvl
I want $image->filedate
to give me the unix timestamp.
I cannot find why I always get a formatted date/time.
How do I force a timestamp?
Regards,
Jan
Re: Hi, i am searching for a date format in Gallerz
Posted: Sun Mar 18, 2018 10:19 pm
by HarmO
Try {$image->filedate|date_format:"%s"}
this should convert in to a unix timestamp.
for more info watch smarty or php website
https://www.smarty.net/docsv2/en/langua ... format.tpl
http://php.net/strftime
Re: Hi, i am searching for a date format in Gallerz
Posted: Mon Mar 19, 2018 8:16 am
by janvl
Thank you,
i must have overseen that, i searched on both links before.
what i do is check the date-difference with smartynow and when the image is older then 3 month it is marked "older image".
I changed the template to (example)
Code: Select all
{math equation="x - y" x=$smarty.now y=($image->filedate|date_format:"%s") assign="difr"}
{if $difr > 600} oud {else} {$image->filedate}{/if}
Now it is working.
Regards,
Jan
Re: Hi, i am searching for a date format in Gallerz
Posted: Mon Mar 19, 2018 12:00 pm
by HarmO
your welcome
Re: Hi, i am searching for a date format in Gallerz
Posted: Mon Mar 19, 2018 7:37 pm
by PinkElephant
Hi Jan
janvl wrote:Code: Select all
{math equation="x - y" x=$smarty.now y=($image->filedate|date_format:"%s") assign="difr"}
{if $difr > 600} oud {else} {$image->filedate}{/if}
Just a minor observation... the smarty docs warn about math being expensive (due to eval) so raw date arithmetic may be a better option. Untested, something like...
Code: Select all
{* image unix timestamp (seconds since 1970-01-01) *}
{image_timestamp = $image->filedate|date_format:"%s"}
{* image age in seconds *}
{image_age = $image_timestamp - $smarty.now}
{* 90 days: 90 * 24*60*60 = 7776000 seconds *}
{if $image_age <= 7776000}
newer
{else}
older
{/else}
Also, it won't require setting permissive_smarty true.
Re: Hi, i am searching for a date format in Gallerz
Posted: Mon Mar 19, 2018 8:48 pm
by janvl
Thanks PinkElephant
I will change it, but I have had no problem using math, the customer has a vserver with more then enough resources to run all his sites, 5 times CMSMS and some other webapps.
I am busy modernising his installations after I was asked to take over the job.
Regards,
Jan