cb2004 Posted December 14, 2015 Share Posted December 14, 2015 I am displaying calendar entries by using a datetime field for the start date and I will later be extending it by also displaying an end date. What I wanted to do was have the year as a heading and then all results for that year will be displayed. What I have below is actually working great, I was just wondering if it was a good technique? $results = $page->children; if (count($results)) { $years = array(); foreach ($results as $result) { $years[] = strftime("%Y", $result->date_1); } $years_unique = array_unique($years); foreach ($years_unique as $year) { echo "<h3>{$year}</h3>"; $start = strtotime(date("$year-01-01") . " 00:00:00"); $end = strtotime(date("$year-12-31") . " 23:59:59"); foreach ($page->children("date_1>$start, date_1<$end") as $child) { echo "<p>{$child->title}</p>"; } } } Cheers all. Link to comment Share on other sites More sharing options...
LostKobrakai Posted December 14, 2015 Share Posted December 14, 2015 For a pure php implementation this is probably as good as it gets. I would just use >= and <= to also get 1.1. 00:00:00 and 31.12. 23:59:59 dates. If you've more cases, where you need to work with dates I'd suggest taking a look at Carbon. Link to comment Share on other sites More sharing options...
cb2004 Posted December 14, 2015 Author Share Posted December 14, 2015 Thank you for your time on this. Just thought I would post it as I couldn't find anything similar on the forum so it may help future users. Link to comment Share on other sites More sharing options...
Macrura Posted December 14, 2015 Share Posted December 14, 2015 some of these might be applicable: https://processwire.com/talk/topic/9486-movie-website-session-times-by-day/ https://processwire.com/talk/topic/4991-sub-arrays-dates-times-and-pure-hell/ also sometimes i avoid having to use the array_unique by using the value as the key 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