We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 2722
    • 11 Posts
    I don’t understand.
    If I want the publish date to appear on the page.
    how do I format it so that it’s an understandable date??????
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Dates in MODx are stored as UNIX timestamps. They can be formatted with snippets (and with PHx) using the PHP date() function and format strings.

      http://il.php.net/manual/en/function.date.php
        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
        • 16278
        • 928 Posts
        I think it’s strftime() (www.php.net/strftime) rather than the date() function that Ditto, PHx and so on use. grin Personally I find date() more flexible and easier to comprehend than all those percenty conventions, but you do have to take steps to tell PHP where your clock lives if you want to avoid a heap of warning messages in your error file. sad
          • 7253
          • 97 Posts
          I wrote myself a little snippet to do this, as it comes up so often:

          <?php
          
          	/*
          
          		Name: DateFormatter
          		Description: <strong>0.1</strong> Outputs the formatted version of the passed in UnixTimeStamp, according to the format string passed in FormatString
          		Version: 0.2
          		Author: Duncan Lock <[email protected]>
          
          		Parameters:
          		
          			$FormatString	PHP format string appropriate for using with the date function (http://www.php.net/date)
          			$DateTime	Unixtimestamp or a date. If it's is_numeric, we assume it's a unix timestamp.
          
          		eg:
          		[[DateFormatter? &formatString=`l dS \of F Y h:i:s A` &dateTime=`[*pub_date*]` ]]
          			Returns something like: 'Monday 15th of August 2005 03:12:46 PM'
          
          		[[DateFormatter? &formatString=`d/m/Y` &dateTime=`1134086400` ]]
          			Returns something like: '09/12/2005'
          
          	*/
          	
          	$formatString = isset($formatString)? $formatString: 'l jS \of F Y h:i:s A';
          	# Convert $dateTime into a unix timestamp, if it isn't already
          	$unixTimeStamp = is_numeric($dateTime)? $dateTime: strtotime($dateTime);
          
          	if (trim($unixTimeStamp) == ''):
          		# empty timestamp, bail
          		return '';
          	else:
          		# return the formatted datetime
          		return date ($formatString, $unixTimeStamp);
          	endif;
          ?>
          
          


          As previously mentioned, you can use PHX for this, if you’re using it - and I’m sure there’s stuff in the repository that does this too. I think that I originally wrote this because I couldn’t find one that used date() - which allows you to output stuff that looks like this: ’Monday 15th of August 2005 03:12:46 PM’ - using st/th/rd for days - something you can get out of strftime(), afaik. Hope else someone finds it useful.