We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 46876
    • 23 Posts
    Hi everyone,

    I've been using MODX for a couple of months now and I've run into a small issue with regards to the date formatting.

    I've searched up and read about using the input/output filters, but some how it doesn't seem to work. I'm trying to format a value that is being pulled from a custom database (using migxDB).

    [[!migxLoopCollection? 
    &packageName=`redaseventspackage`
    &classname=`redasEventsPackage`
    &sortConfig=`[{"sortby":"datestart","sortdir":"ASC"}]`
    &where=`{"resource_id":"62","dateend:>":"[[!GetDate:date=`%Y-%m-%d`]]"}`
    &limit=`3`
    &tpl=`@CODE:<li><span class="course-name"><a href="event.html?eventID=[[+id]]">[[+title]]</a></span><br/><span class="course-loc">[[+location]]</span><br/><span class="course-date">[[+datestart:strtotime:date=`%e %B %Y`]]</span></li>`]]
    


    As you can see, the last value, 'datestart' has a filter applied, but when the code is run, the output is empty. If I remove the filter, the results display as normal (in the default format).

    The data is of 'date' format in the database. It was 'datetime' before and that did not work either. I've tried running the value uncached but that doesn't work as well. I've also tried using filters separately, but with no results.

    I'm currently using Revo 2.2.10-pl. I've read somewhere about the value not being passed as the filter has nothing to read, but I did not manage to find a solution.

    If anyone could give some advice, I would be grateful. Thanks!

    This question has been answered by Bruno17. See the first response.

      • 3749
      • 24,544 Posts
      It sounds like the GetDate snippet is returning a human-readable date string. The date() output modifier wants a Unix timestamp for its input, not a date string (as does the strftime() modifier).

      Assuming that the date is stored in the DB as a Unix timestamp, the most efficient thing would be to rewrite the GetDate snippet to use strftime() or date() on it with your preferred format and return the result -- no output modifiers. The disadvantage of date() is that it doesn't respect the locale setting (though maybe you don't care about that).

      As an alternative, you can try this, but it involves two unnecessary conversions, so it will be significantly slower:

      [[!GetDate:strtotime:date=`%Y-%m-%d`]] 
        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
        • 46876
        • 23 Posts
        Hi Bob, thanks for the reply!

        Actually, there is nothing wrong with the GetDate snippet. The snippet is working correctly (mainly used to pull out the data based on the current date), the main issue is the [[+datestart]] value seen in line 7.

        When I use [[+datestart]] to call out the date, it works. But when I try to put an output filter on it, it returns an empty value. Even if I remove the GetDate snippet for testing purposes, it still returns an empty value.

        However, if I change [[+datestart]] to something like [[*createdon]] or [[*publishedon]] and add the output filter, it works. Does this have to do something with how the variables are being called? (Note that [[*datestart]] does not work either.)
          • 46876
          • 23 Posts
          My colleague and I have spent some time looking into the code and we might have found out a most likely reason to why the filter does not work.

          When the snippet is called (migxLoopCollection), the filter (strtotime:date) is being processed first when the code is being generated on the page, and thus it does not have the correct value to parse. So instead of getting a date, such as '2014-03-11', it reads the input as '[[+datestart]]' instead. This was discovered using a var_dump and it returned a String(14), which is essentially '[[+datestart]]'.

          Is there a way to resolve this issue?
          • discuss.answer
            • 4172
            • 5,888 Posts
            MODX parses from inside to outside.
            At the time, when MODX tries to parse the date - outputfilter, this value is empty, of course.
            As soon as you're using output-filters on values, which are generated later from snippet, you can't use inline - chunk-code.
            You need to create a chunk and put your code into it.

            &tpl=`yourRowTpl`


            chunk rowTpl:

            <li><span class="course-name"><a href="event.html?eventID=[[+id]]">[[+title]]</a></span><br/><span class="course-loc">[[+location]]</span><br/><span class="course-date">[[+datestart:strtotime:date=`%e %B %Y`]]</span></li>
            
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 46876
              • 23 Posts
              Ah, it works! Many thanks, Bruno! laugh