Formatting the date with a custom attribute

Permalink
Hello. I've got a news template that includes attributes for fields such as Author, Publication and Date.

In my template for the news page, I've hard-coded these fields:

<h1><?php $page = Page::getCurrentPage(); echo $page->getCollectionName(); ?></h1>
   <h2><?php echo $c->getCollectionAttributeValue('Author') ?> </h2>
   <h2><em><?php echo $c->getCollectionAttributeValue('Publication') ?></em> </h2>
   <h3><?php echo $c->getCollectionAttributeValue('ArticleDate') ?> </h3>



This works very nicely, except it formats the date like so:

yyyy-mm-dd hh:mm:ss

Is there a ways to specify a different formatting?

Thanks

View Replies:
jgarcia replied on at Permalink Reply
jgarcia
I don't think there's a way to do this using a part of the C5 API, but you could do it using PHP's strtotime and date functions, like so:
$timestamp = strtotime($c->getCollectionAttributeValue('ArticleDate'));
$formattedDate = date('F j, Y, g:i a',$timestamp);
echo $formattedDate;


Using this method, you could format it however you want in the date function. Seehttp://php.net/manual/en/function.date.php...
Metaglyphics replied on at Permalink Reply
Thanks for the quick response. This bit of code gives me a syntax error, unexpected ';', though as far as I can tell, it certainly looks correct. Any idea what might be causing that?
jgarcia replied on at Permalink Reply
jgarcia
I forget an extra ) at the end of the first line. I edited it to reflect the correction.
Metaglyphics replied on at Permalink Reply
Oh algebra, you win again!

Thanks. It works like a charm.
chansolo replied on at Permalink Reply
chansolo
Thank you, you just ended hours of searching.