Peter Knight Posted October 23, 2014 Share Posted October 23, 2014 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 Basically, I have a Datetime field set to output M j, YOn 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. Link to comment Share on other sites More sharing options...
adrian Posted October 23, 2014 Share Posted October 23, 2014 date("F", $test->getUnformatted("testimonial_date")); // October Check out the php manual for other codes to use in place of "F": http://php.net/manual/en/function.date.php Link to comment Share on other sites More sharing options...
Peter Knight Posted October 23, 2014 Author Share Posted October 23, 2014 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. Link to comment Share on other sites More sharing options...
SiNNuT Posted October 23, 2014 Share Posted October 23, 2014 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. 1 Link to comment Share on other sites More sharing options...
Peter Knight Posted October 23, 2014 Author Share Posted October 23, 2014 Thank you both. Didn't realise it has to be nested. All working now Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now