We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34147
    • 28 Posts
    I have been looking through the list of available options for outputting the number of the current month, as usual way is (%m) but that outputs '01 – 09' where as I just looking for '1 – 9'. I have read through the standard PHP options and it says to use (%n), but that seems to just create a line break. anyone have any ideas how to output single digit dates if output filters like:
    [[+tv.event_start_date:strtotime:date=`%Y – %m - %d, %l:%M`]]

    This question has been answered by multiple community members. See the first response.

    • discuss.answer
      Quote from: travis_love at Aug 28, 2013, 11:26 PM
      I have been looking through the list of available options for outputting the number of the current month, as usual way is (%m) but that outputs '01 – 09' where as I just looking for '1 – 9'. I have read through the standard PHP options and it says to use (%n), but that seems to just create a line break. anyone have any ideas how to output single digit dates if output filters like:
      [[+tv.event_start_date:strtotime:date=`%Y – %m - %d, %l:%M`]]

      Travis,

      I believe that you need to use the stuff from strftime: http://php.net/manual/en/function.strftime.php Therefore there is no code for month without the leading zero. Not sure of how to approach this. I read something about a flag in there to remove.
      [[+tv.event_start_date:strtotime:date=`%Y – %-m - %d, %l:%M`]]

      note the %-m

      All the best,

      Jay
        Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. BlogTwitterLinkedInGitHub
      • discuss.answer
        • 3749
        • 24,544 Posts
        The MODX date output modifier uses strftime() as Jay suggests (instead of date(), which you'd expect), which has no single-digit month option.

        Try %-m for the month. It won't work on Windows, but should on a linux server, and %-d should give you a single-digit day.


        If that doesn't work, you'd have to create a custom modifier that uses PHP's date() function, but that won't respect any locale setting, which you'd need for a multi-language site.

          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
          • 34147
          • 28 Posts
          thank you very much for your guys' help, that actually seems to work for my given situation. It just so happened that the particular JavaScript required single-digit inputs for the number of the month, so even if I didn't find a solution within PHP, I could easily (I hope) come up with a JavaScript solution. But this is good information for those people who might need to know in the future.
          • You could also use a custom output filter, here's one I've put together. Add this as a snippet (call it phpdate):

            <?php
            if (empty($input) || empty($options)) return '';
            
            return date($options, strtotime($input));


            Basically, it expects a date string as the input (not a timestamp) and will return the php date() format you specify. For example:

            [[*createdon:phpdate=`n`]]


              Garry Nutting
              Senior Developer
              MODX, LLC

              Email: [email protected]
              Twitter: @garryn
              Web: modx.com