We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10997
    • 27 Posts
    I am attempting to display just the month and day ( format MM - DD ) from a timestamp containing the actual birthday of a user. I’m using WebLoginPE - and it will display the correct timestamp on its own, when I try to parse that datestamp with PHx, it displays nothing.

    The call..

    [+view.dob:date=`%e - %m`*]

    The result: <blank space where the call should be>

    Anyone have any ideas how I can try to format these dates in this manner? I just don’t want to show folks’ birthyears.

    Thanks for any ideas...
      • 15469
      • 64 Posts
      Katzenfutter Reply #2, 15 years ago
      If you simply can´t get it with PHx, for whatever reason... what about a little snippet to format your date-string?
      Just pass it over to your snippet and do what ever you like directly in PHP and let it return the value you like.

      [!date_snippet?date=`[+date+]`!]

      <?php
      $date = isset($date) ? $date : null;
      //Format your date here as you like
      return $date;
      ?>
      


      Cheers.
        $cd /pub
        $more beer
        • 16278
        • 928 Posts
        Is that asterisk before the closing quote there in the actual page? I don’t use WebloginPE, but I would have thought a plus sign would work better. shocked
        [+view.dob:date=`%e - %m`*]
        KP
          • 15469
          • 64 Posts
          Katzenfutter Reply #4, 15 years ago
          grin
          Should clean my glasses that aren´t there...
          Plus would work right well I think.

          But my version with a snippet and just PHP works fine, too wink
            $cd /pub
            $more beer
            • 10997
            • 27 Posts
            Thank you everyone!

            I actually just misstyped the * - that’s what I get for not copying/pasting! It was a ’+’

            Katzenfutter - I’m admittedly a bit PHP green, but I don’t understand the syntax here..
            <?php
            $date = isset($date) ? $date : null;
            //Format your date here as you like
            return $date;
            ?>


            The isset part... what is the ? for? Is it basically "If isset($date)=False, THEN $date=null, Else <format date>?

            I’ve never used a ? in a php statement like that - any help you can give would be awesome!

            Thanks from a newb.

            BTW, I Googled my heart out, but googling for punctuation marks is less-than-optimal! cool

              • 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
                • 15469
                • 64 Posts
                Katzenfutter Reply #7, 15 years ago
                For using google: try to use quoatation marks for your search strings as they might contain some special characters like ampersands and other signs...

                The other question about that question mark: it´s the ternary operator. It´s used for a shorter syntax of an if/else-statement.
                I was just giving you an hint on how to write your code in that specific snippet, but I´ll try to explain what i meant here.

                $date = isset($date) ? $date : null;
                


                isset() asserts that the variable $date has been set before, if that expression (isset($date)) returns false, $date is being set to "null".

                Otherwise i could have said the following:
                if(isset($date))
                {
                $date = $date;
                }
                else
                {
                 $date = null;
                }
                


                I just followed the "best practices" here: http://wiki.modxcms.com/index.php/Creating_Snippets#Snippet_parameters_should_always_have_a_default_value

                Hope that helps.

                Cheers
                  $cd /pub
                  $more beer
                  • 10997
                  • 27 Posts
                  Thank you both very much. I greatly appreciate your help.