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
    This is weird... MODx plays with dates stored in Template Variables.

    check out this Snippet code:

    if( $TVarray = $modx->getTemplateVarOutput(array(’releasedate’), $modx->documentIdentifier,$published=$modx->documentObject[’published’]) ){
    //If TV is not empty, assign value to $pageContents
    if(!empty($TVarray[’releasedate’])) {
    $pageContents[’releasedate’] = $TVarray[’releasedate’];
    }
    }

    $output = $modx->parseChunk(’mychunk’, $pageContents, ’[+’, ’+]’);
    return $output;

    Chunk ’mychunk’ has a placeholder: [+releasedate+]

    Which ends up printing:
    ’WEDNESDAY, SEPTEMBER 30, 2009’

    Yet, it’s not like that in the database. For the record:
    mysql> select value from site_tmplvar_contentvalues WHERE contentid='418' and tmplvarid='22';

    Returns: 30-09-2009 15:32:01

    The culprit? The Date widget.

    TV is using widget Date Formatter with these values:
    %A, %B %d, %Y

    But those aren’t the correct placeholders. According to http://www.php.net/manual/en/function.date.php %A should be "AM or PM" not the full day name.

    Am I going senile?
      • 36592
      • 970 Posts
      %A is " A full textual representation of the day ".
      http://www.php.net/manual/en/function.strftime.php
        • 3749
        • 24,544 Posts
        Everett, I made the same mistake at first. It’s logical to assume that PHP would have a single set of formatting codes for date formatting, but that would be too easy. wink

        Date TVs are formatted using the strftime() codes as tkfm suggests.
          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
          • 9207 ☆ A M B ☆
          • 2,475 Posts
          Man, I hate date functions... even in Perl, all the date modules were enormous and sucked. The most useful C derived thing I have EVER seen was a simple one like this:

          convert( $this_string, 'from %this %format', 'to %this %format');


          I guess PHP could do this:
          date("Y-m-d",strtotime($time));

            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Since date TVs use a javascript widget, the output of the javascript widget is saved as the TV value. So the TV output widget has to first convert it into a timestamp so it can be formatted as specified (or by the default %A %d, %B %Y).
            // Check for MySQL style date - Adam Crownoble 8/3/2005
            $date_match = '^([0-9]{2})-([0-9]{2})-([0-9]{4})\ ([0-9]{2}):([0-9]{2}):([0-9]{2})$';
            $matches= array();
            if(strpos($value,'-')!==false && ereg($date_match, $value, $matches)) {
                $timestamp = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[1], $matches[3]);
            }
            else { // If it's not a MySQL style date, then use strtotime to figure out the date
                $timestamp = strtotime($value);
            }
            $p = $params['format'] ? $params['format']:"%A %d, %B %Y";
            $o = strftime($p,$timestamp);
            


              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