Hello
I am attempting to format a date using a snippet and getting an error. Here’s the code flow:
1. MODx page uses this code to call "friendlydate" snippet with the page’s publication date
[[friendlydate? &thisdate=`[*pub_date*]` ]]
2. The "friendlydate" snippet is just this code:
echo strftime("%V,%G,%Y",$thisdate);
3. I am receiving this error, even tough $thisdate does in fact contain the pub_date unix time value:
"strftime() expects parameter 2 to be long, string given"
The same happens when I use date() instead of strftime(). If I pass a hard-coded value (instead of [*pub_date*]), I get the same error.
Any ideas?
Thanks!
I believe the parsing of the TV will return a string, like the parsing of a runSnippet call, I think the return value is coerced into a string type by the core, hence the error, although when seen it will look like the correct date value.
Use MODx, or the cat gets it!
Thank you for your reponse shamblett.
Yes, I think you are right. It appears that strftime is throwing the error b/c it is expecting an int value, and for some reason automatic type changing is not happening. When I attempt to type the variable using (int) in the snippet, I simply get a result of 0.
I was incorrect in my last post about hard-coded values in the parameter - if I submit a string like this, it actually does work:
[[friendlydate? &thisdate=`1199775600` ]]
Surely someone has a workaround for this - people must often be wanting to show the publication date of a page, in a friendly format. However I can’t find anything on these forums or the larger Web. Do you have any suggestions of where to look?
Thanks!