We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4385
    • 372 Posts
    I am trying to format the date multiple times on each article. It looks like I can only have one date format at a time and still limited to strfrtime (no - st, nd, rd). Is there a way to format using EVAL?

    FROM:
    <div class="eventdate">
    <p class="month">SEP</p>
    <p class="day">18th</p>
    <p class="year">2007</p>
    </div>

    TO:
    <div class="eventdate">
    <p class="month">[+date+]</p>
    <p class="day">[+date+]</p>
    <p class="year">[+date+]</p>
    </div>

    I am going publish "empty" articles to create a simple calendar and would like to have the expire on the day after they are over.

    Is there a better solution?

      DropboxUploader -- Upload files to a Dropbox account.
      DIG -- Dynamic Image Generator
      gus -- Google URL Shortener
      makeQR -- Uses google chart api to make QR codes.
      MODxTweeter -- Update your twitter status on publish.
      • 11975
      • 2,542 Posts
      Hi,

      you can use PHx to achieve the expected result.

      http://wiki.modxcms.com/index.php/PHx#date.28.3D.60dateformat.60.29


      <div class="eventdate">
      <p class="month">[+createdon:date=`%m`+]</p>
      <p class="day">[+createdon:date=`%d`+]</p>
      <p class="year">[+createdon:date=`%Y+]</p>
      </div>

      :-)
        Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
        • 4385
        • 372 Posts
        Thanks for the help!

        I am guessing strftime is used for better localization.
        Home much overhead would I be creating to apply a function?

        function ordinal($cardinal){
        $test_c = abs($cardinal) % 10;
        $ext = ((abs($cardinal) %100 < 21 && abs($cardinal) %100 > 4) ? ’th’
        : (($test_c < 4) ? ($test_c < 3) ? ($test_c < 2) ? ($test_c < 1)
        ? ’th’ : ’st’ : ’nd’ : ’rd’ : ’th’));
        return $cardinal.$ext;
        }

        I think my site might go international anyway... I should probably drop formatting.
          DropboxUploader -- Upload files to a Dropbox account.
          DIG -- Dynamic Image Generator
          gus -- Google URL Shortener
          makeQR -- Uses google chart api to make QR codes.
          MODxTweeter -- Update your twitter status on publish.
          • 4385
          • 372 Posts
          Worked like a charm!

          <p class="day">[+unpub_date:date=`%d`:ordinal+]</p>

          phx:ordinal

          <?php
          if (!function_exists('ordinal'))
          {
          	function ordinal($cardinal){
          		$test_c = abs($cardinal) % 10;
          		$ext = ((abs($cardinal) %100 < 21 && abs($cardinal) %100 > 4) ? 'th'
          				: (($test_c < 4) ? ($test_c < 3) ? ($test_c < 2) ? ($test_c < 1)
          				? 'th' : 'st' : 'nd' : 'rd' : 'th'));
          		return $cardinal.$ext;
          	}
          }
          return ordinal($output);
          ?>
          
          
            DropboxUploader -- Upload files to a Dropbox account.
            DIG -- Dynamic Image Generator
            gus -- Google URL Shortener
            makeQR -- Uses google chart api to make QR codes.
            MODxTweeter -- Update your twitter status on publish.
            • 27708 MODX Staff
            • 2,502 Posts
            bwente,

            This is a very nice little snippet. You should add that to the PHx wiki page. This would actually be very handy as would the ability to drop the zero in the hours from the unixtime output from strftime().

            Cheers,

            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. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
              • 4385
              • 372 Posts
                DropboxUploader -- Upload files to a Dropbox account.
                DIG -- Dynamic Image Generator
                gus -- Google URL Shortener
                makeQR -- Uses google chart api to make QR codes.
                MODxTweeter -- Update your twitter status on publish.