Problems sorting by a custom date attribute

Permalink
I have a custom date attribute, 'event_date_time'.

I display a list of events sorted by 'event_date_time' but separated out into months using the following code:

$eventList = new PageList();
$sections = $this->get('sections');
$keys = array_keys($sections);
$keys[] = -1;
$eventList->filterByParentID($keys);
$eventList->sortBy('event_date_time', 'asc');
$this->set('eventList', $eventList);
$this->set('eventResults', $eventList->getPage());


I get 'sections' by:

protected function loadEventSections()
   {
      $eventSectionList = new PageList();
      $eventSectionList->filterByEventSection(1);
      $tmpSections = $eventSectionList->get();
      $sections = array();
      // $_c is a collection object
      foreach ($tmpSections as $_c) 
      {   
         // $_c is each page, get the page id as the key
         // and the page name as the "value"
         $sections[$_c->getCollectionID()] = $_c->getCollectionName();
      }
      $this->set('sections', $sections);


The problem is, it doesn't seem to sort by 'event_date_time' in a reliable way.

If I sort by a non-custom attribute , i.e.:

$eventList->sortBy('cvName', 'asc');


This works well. However, when I sort by event_date_time, it doesn't work if I go in and modify the date. Once I change the date (say to another month) it doesn't sort by the normal order.

I know this is probably a weird explanation for what is happening. I feel like it's trying to sort by the 'event_date_time' but also by the last modified time, but I'm not sure how to test for this so I realize the explanation I am giving might seem a bit odd (or incomplete).

But any suggestions would be greatly appreciated.

Also, I am using a slightly older version of concrete5 for this site (5.5.2)

 
nicolechung replied on at Permalink Reply
I'm not sure if sorting by a custom date works in that version (at least, not the way I was using it), so I just used ksort:

$eventList = new PageList();
$raw = $eventList->get(); 
$sorted = array();
$unsorted = array();
// get everything for that month
foreach ($raw as $cobj) {
   $str = $cobj->getAttribute('event_date_time');
   $date = strtotime($str);
   $month = intval(date('m', $date));
   $day = intval(date('d', $date));
   $counter = 0;
   if ($month == $_GET['month']) {
      $str = $cobj->getAttribute('event_date_time');
      $date = strtotime($str);
      $unsorted[$date+$counter] = $cobj;