We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38850
    • 110 Posts
    If you have tried to use the date output filter and get an empty string, this is why. I found this out when trying to filter the "publishedon" date for a blog entry.

    I am referencing this page of the documentation:
    http://rtfm.modx.com/revolution/2.x/making-sites-with-modx/commonly-used-template-tags/date-formats

    Here they give an "All Parameters" table of string codes you can use to filter the date.

    The problem is, some of them don't produce output! And even if you use a "bad" code in combination with other "good" codes, you will still get an empty string.

    Here is a specific code being used in a chunk:
    <h3>Published: [[+publishedon:strtotime:date=`%D %l:%M%P`]]</h3>
    


    According to the docs, this should product something like "11/04/14 4:36pm". However, the actual output is an empty string.

    The reason I discovered is that some parameters simply don't work, and if you use them, the output is zilch.
    I created a snippet to loop through all the parameters and output what they contain and spit out an array of responses. Here is the snippet which I called "TestDate":

    $codes = array(
    "%a", "%A", "%b", "%B", "%c", "%C", "%d", "%D", "%e", "%H", "%I", "%l", "%j",
    "%m", "%M", "%n", "%P", "%p", "%r", "%R", "%S", "%t", "%T", "%u", "%w", "%x",
    "%X", "%y", "%Y", "%z", "%Z"
    );
    
    $val = array();
    
    foreach ($codes as $c) {
        $val[] = "[[*publishedon:strtotime:date=`$c`]]";
    }
    
    $result = array_combine($codes, $val);
    
    return "<pre>" . print_r($result, true) . "</pre>";
    


    The result of running this is a test of all individual parameters for the date filter as listed in the docs. Here is the result:

    Array
    (
        [%a] => Mon
        [%A] => Monday
        [%b] => Oct
        [%B] => October
        [%c] => 10/6/2014 8:53:00 AM
        [%C] => 
        [%d] => 06
        [%D] => 
        [%e] => 
        [%H] => 08
        [%I] => 08
        [%l] => 
        [%j] => 279
        [%m] => 10
        [%M] => 53
        [%n] => 
        [%P] => 
        [%p] => AM
        [%r] => 
        [%R] => 
        [%S] => 00
        [%t] => 
        [%T] => 
        [%u] => 
        [%w] => 1
        [%x] => 10/6/2014
        [%X] => 8:53:00 AM
        [%y] => 14
        [%Y] => 2014
        [%z] => US Mountain Standard Time
        [%Z] => US Mountain Standard Time
    )
    


    Not only are some codes returning nothing, but other codes don't return what the docs say they should. Look at "%c". This is supposed to return "local date and time" in the format like "Wed jan 7 00:22:10 2010". The actual format looks nothing like what the docs say!

    It seems that any code which combines things (except for %c) doesn't work. And shorthand doesn't work either, for example anything removing leading 0s.

    It's weird, but I wanted to post these results in case anybody else has this issue with date filter. Hopefully the docs can be updated with a more accurate list!
    • Something odd here, it works fine for me... (I did use createdon instead of publishedon)
      Array
      (
          [%a] => Fri
          [%A] => Friday
          [%b] => Oct
          [%B] => October
          [%c] => Fri Oct 24 18:15:55 2014
          [%C] => 20
          [%d] => 24
          [%D] => 10/24/14
          [%e] => 24
          [%H] => 18
          [%I] => 06
          [%l] =>  6
          [%j] => 297
          [%m] => 10
          [%M] => 15
          [%n] => 
      
          [%P] => P
          [%p] => PM
          [%r] => 06:15:55 PM
          [%R] => 18:15
          [%S] => 55
          [%t] => 	
          [%T] => 18:15:55
          [%u] => 5
          [%w] => 5
          [%x] => 10/24/14
          [%X] => 18:15:55
          [%y] => 14
          [%Y] => 2014
          [%z] => +0300
          [%Z] => CEST
      )


      %n is a newline, and %t is a tab, so those are actually producing what they're supposed to...
        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
      • Since this is using the PHP strftime function, which in turn is based on your server OS's C library, it might be worthwhile to examine their documentation on the subject. For example, %P only outputs 'P' in my case because I'm on OS X, and the PHP docs say
        Warning

        Mac OS X only: The %P modifier is not supported in the Mac OS X implementation of this function.
          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
          • 3749
          • 24,544 Posts
          It depends on your platform. Several of them don't work on Windows, for example.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 38850
            • 110 Posts
            So it depends on what exactly?

            Just the operating system? PHP version? C library?

            For me, I do happen to be on Windows 7. Might be interesting if a bunch of people on different OSes tried it and compiled a proper chart of which don't work.

            I just got confused and spent like an hour trying to figure out why the date filter didn't work even though I had used it before. Thought I was going mad for a minute and starting RTFMs all over again!
            • Probably depends on all three. However, the PHP docs do say that if it's not available in the underlying platform's C library, it will just return the letter - in my case, the P since %P doesn't work.
                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
                • 3749
                • 24,544 Posts
                On XAMPP, I get an error if there's a token that strftime() doesn't recognize. It might be because E_NOTICE is on.

                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting