Jump to content

Recommended Posts

Posted

I've been reading through the forums regarding date and time output and trying to understand it better. At the moment, none of the samples are working for me  :mellow:

Basically, I have a Datetime field set to output M j, Y
On the front end, this is basically Sep 25, 2013 etc

I was wondering how I could change following

{$test->testimonial_date}

to isolate just the date or the month or year.

Here's my code:

<?php
$tests = $pages->find("template=detail-testimonial, sort=-date"); 
foreach ($tests as $test)
echo "
   {$test->testimonial_date}<br/> 
   <h3>{$test->title}</h3>
   <p>{$test->testimonial_body}</p>
<hr/>
;?>

I want to keep the Datetime field as is instead of creating a different datefield for day, month year.

Posted

I can see what it's doing. Just not sure how to integrate with my block of code.

Do I add your line at the start before echo like so?

<?php
date("F", $test->getUnformatted("testimonial_date")); // October

$tests = $pages->find("template=detail-testimonial, sort=-date"); 
foreach ($tests as $test)
echo "
   {$test->testimonial_date}<br/> 
   <h3>{$test->title}</h3>
   <p>{$test->testimonial_body}</p>
<hr/>
;?>

I've tried a few things and am getting an error.

Posted

Something like this should work

<?php
$tests = $pages->find("template=detail-testimonial, sort=-date"); 

foreach ($tests as $test) {
    $mydate = date("F", $test->getUnformatted("testimonial_date"));
    echo "{$mydate}<br/><h3>{$test->title}</h3><p>{$test->testimonial_body}</p><hr/>";
}

Actually, i'm not sure that setting an extra var ($mydate) would be most efficient. You can also do it directly and then concatenate your stuff together.

  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...