I have a TV of type "Date" using the Unixtime widget. I’m trying to output that in a snippet as a formatted date. My snippet looks like this:
<?php
global $modx;
$rawvalue = $modx->getTemplateVarOutput(’CalStartDate’);
$calstartdate = "[+CalStartDate+]";
//print $calstartdate - this returns the unixtime, as expected
//return date( "l, F j Y", 1261173600 ); - this works
return date( "l, F j Y", $calstartdate); // fails. see below.
?>
I get this: "date() expects parameter 2 to be long, string given"
Can anyone give me a pointer?
Try replacing this line:
$calstartdate = "[+CalStartDate+]";
with this:
$calstartdate = $rawvalue[’CalStartDate’];
Thanks Breezer, but the issue remains.
I’m curious to know why this:
$calstartdate = "[+CalStartDate+]";
returns a value that looks like a unixtime value (1261074600) when I print it out, but when I try to convert it:
return date("l, F j Y", $calstartdate);
It’s not working I’m sure it’s a simple answer, just something beyond my ability. Is there a datatype conversion that I’m unaware of?
-
☆ A M B ☆
- 24,524 Posts
Where is the value of the placeholder [+CalStartDate+] coming from? You can’t use MODx tags in PHP code.
This topic in the wiki might explain better:
http://wiki.modxcms.com/index.php/API:getTemplateVarOutput
You might also try this:
<?php
$rawvalue = $modx->getTemplateVarOutput(array('CalStartDate'));
$calstartdate = $rawvalue['CalStartDate'];
return date( "l, F j Y", $calstartdate);
?>
Interesting.
Even when my snippet is just:
<?php
global $modx;
print "[+CalStartDate+]";
?>
I get the unix time.