title: Sorting a structure based on a date and time element
body: <p>I have a structure that I need to sort in ascending order:</p>
  
  <pre><code>typedef struct CallLogSearchDataStruct
  {
      char * date;
      char * time;
      char * bParty;
      char * aParty;
      float duration;
      char * cleardownCause;
      struct CallLogSearchOutboundStruct * outboundLegs;
      int maxDataCol;
  } callLogSearchDataStruct;
  </code></pre>
  
  <p>I need to sort the structure based on the date and time in ascending order. The date and time is in the following format</p>
  
  <p>Date: <code>16/05/2011</code> Time: <code>01:20:03</code></p>
  
  <p>I need to sort the above two fields in ascending order, and I've been looking at qsort but I can't figure out a way of being able to do it. I am calling the function in the following way.</p>
  
  <pre><code>qsort(callLogSearchData, dataRow, sizeof(callLogSearchDataStruct), sortCompare);
  </code></pre>
  
  <p>And my function is as follows</p>
  
  <pre><code>int sortCompare(const void * a, const void * b)
  {
      const callLogSearchDataStruct *u1 = a;
      const callLogSearchDataStruct *u2 = b;
  
      if (u1-&gt;date &lt; u2-&gt;date)
      {
          return -1;
      }
      else if (u1-&gt;date &gt; u2-&gt;date)
      {
          return 1;
      }
      else
      {
          return 0;
      }
  
  }
  </code></pre>
  
  <p>When I do the above code, it doesn't seem to sort it and instead screws up the layout of the structure, i.e. when I export the contents of the structure to a file, everything comes out in the wrong column order, whereas it is fine, except for being in the wrong sort order if the compare is not done. </p>