We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9207 ☆ A M B ☆
    • 2,475 Posts
    Inspired by one of Bob’s helpful forum posts (http://modxcms.com/forums/index.php?topic=56339.0), I’ve added a page to the official wiki dealing with the topic of date formats:
    http://rtfm.modx.com/display/revolution20/Date+Formats

    However, I’ve noticed a couple odd things... is it "normal" or expected to have to convert the resource fields to a Unix timestamp before using the date filter?

    For example, this gives me the expected output "Thu Apr 14, 2011":
    [[*createdon:strtotime:date=`%a %b %e, %Y`]]


    Whereas the following flubs to Unix date zero "Wed Dec 31, 1969":
    [[*createdon:date=`%a %b %e, %Y`]]


    Secondly, the pub_date doesn’t seem to ever get a value; its value should be distinct from the publishedon field, but I can’t seem to find where the pub_date is going.

    Any ideas?
      • 31053
      • 31 Posts
      Quote from: Everett at Apr 18, 2011, 08:54 AM

      Whereas the following flubs to Unix date zero "Wed Dec 31, 1969":
      [[*createdon:date=`%a %b %e, %Y`]]

      From here http://php.net/manual/en/function.date.php:
      string date ( string $format [, int $timestamp ] )

      This means that the function except the format also takes an argument "timestamp", which should be a number. In the database, the date is represented as a string.
      Therefore, before formatting the need to translate a string with a number with "strtotime".

      About pub_date.
      There are many fields that are responsible for different actions:
      pub_date and unpub_date - These fields are scheduled for automatic publication of
      createdon - when resorce was created
      publishedon - when was checked checkbox "publish"
        for($i=0; $i<100; $i++) echo &#39;Why is it not working?&#39;;
        • 9207 ☆ A M B ☆
        • 2,475 Posts
        Ok, that makes sense: the dates are stored as strings in the database (inside, I’m crying about that... WHY?!? What a waste of MySQL’s easy to use date functions!).

        Ah... and you’re saying that the pub_date and unpub_date are set when you schedule publishing dates for a resource?
          • 28215
          • 4,149 Posts
          Quote from: Everett at Apr 23, 2011, 06:19 PM

          Ok, that makes sense: the dates are stored as strings in the database (inside, I’m crying about that... WHY?!? What a waste of MySQL’s easy to use date functions!).

          Actually, they’re stored as INTs. It’s legacy from Evolution.
            shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
            • 9207 ☆ A M B ☆
            • 2,475 Posts
            Yeah... I remember chatting with Jason about that. I’m only crying about it a little... it took me a while to figure out the correct combo of output filters to use though. It’s in the docs now, so hopefully that helps people out.
              • 31053
              • 31 Posts
              And one more thing. I recently published a bug report about the date formatting. http://bugs.modx.com/issues/4169
                for($i=0; $i<100; $i++) echo &#39;Why is it not working?&#39;;
                • 3749
                • 24,544 Posts
                Just to clarify on pub_date -- it’s only set when the user sets a future date for publication in the Publish On field. And when the doc is actually published, it’s zeroed out.

                The publishedon field always contains the most recent date that the resource changed form unpublished to published (or the date a new doc was saved with Publish checked).
                  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