We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6814
    • 25 Posts
    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?

      • 4041
      • 788 Posts
      Try replacing this line:


      $calstartdate = "[+CalStartDate+]";

      with this:

      $calstartdate = $rawvalue[’CalStartDate’];

        xforum
        http://frsbuilders.net (under construction) forum for evolution
        • 6814
        • 25 Posts
        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?

          • 28042 ☆ 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.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 4041
            • 788 Posts
            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); 
            
            ?>


              xforum
              http://frsbuilders.net (under construction) forum for evolution
              • 6814
              • 25 Posts
              Interesting.

              Even when my snippet is just:

              <?php
              global $modx;
              print "[+CalStartDate+]";
              ?>

              I get the unix time.