Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble Sorting a DATE column in DataTable/DataView in C#
    primarykey
    data
    text
    <p>I am trying to Sort a DataView in C#. It seems the Sort method of DataView Class takes the dates as strings.</p> <p>In the output am getting this -</p> <pre><code>5/9/2013 4:56:38 PM 5/8/2013 4:23:06 PM 5/8/2013 1:38:21 PM 5/7/2013 9:55:30 PM 5/7/2013 7:54:45 PM 5/7/2013 7:44:10 PM 5/7/2013 7:44:10 PM 5/7/2013 12:26:38 PM 5/7/2013 1:44:06 PM 5/6/2013 4:08:54 PM 5/6/2013 10:32:49 AM 5/4/2013 7:54:23 PM 5/4/2013 12:57:21 PM 5/3/2013 3:49:03 PM 5/3/2013 3:49:03 PM 5/3/2013 2:06:12 PM 5/3/2013 11:19:34 AM 5/3/2013 11:03:32 AM 5/3/2013 1:58:38 PM 5/2/2013 7:27:55 PM 5/2/2013 7:17:50 PM 5/2/2013 7:06:06 PM 5/2/2013 6:42:37 PM 5/2/2013 6:30:58 PM 5/13/2013 12:49:24 PM </code></pre> <p>This is my code.</p> <pre><code> DataTable dt; DataView dv = dt.DefaultView; dv.Sort = "MessageDate desc"; DataTable sortedDT = dv.ToTable(); foreach (DataRow row in sortedDT.Rows) { code to print. } </code></pre> <p>As you can see the last date 5/13/2013 should be at the first and not at the bottom as 5/13 > 5/9 if its a date comparison, but 5/13&lt;5/9 if you take it as a string.</p> <p>MessageDate Column is datetime in my declaration, still the compiler is converting it to String.</p> <pre><code> public struct Messages { public string ProfileId { get; set; } public string Network { get; set; } public string FromId { get; set; } public string FromName { get; set; } public string FromProfileUrl { get; set; } public DateTime MessageDate { get; set; } public string Message { get; set; } public string FbComment { get; set; } public string FbLike { get; set; } public string MessageId { get; set; } public string Type { get; set; } } </code></pre> <p>Any ideas why this is happening and how I can workaround the same?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload