Last post Sep 30, 2009 11:25 AM by eappell
Sep 29, 2009 06:54 PM|eappell|LINK
I've got a calendar app where we're loading up a DataTable from one method, then merging the results with another method - both methods return the same type of data and the same columns. One of the columns in the results is "start_time", which has a date
and time. What I want to do is sort the entire, merged, DataTable by the time in the "start_time" column, disregarding the date completely. I've gotten this far, but can't see how to get it done:
Public Function GetDates(ByVal dStart As DateTime, ByVal dEnd As DateTime, ByVal nPageId As Integer) As DataTable
Dim dt As DataTable
dt = GetRecurringEvents(dStart, dEnd)
Dim dv As DataView = dt.DefaultView
dv.Sort = "start_time"
'Here`s where I start to try to create a new column to sort by...
Dim sortedDt = dv.ToTable()
I think I need to create a new column and grab the time from the start_time column and then re-sort the table, but just not sure how to get to that point...
Sep 29, 2009 08:06 PM|whighfield|LINK
Something like this might work
dt.Columns.Add(New DataColumn("start_time_time", GetType(System.DateTime)))
For Each dr As DataRow In dt.Rows
Dim d As Date = dr("start_time")
dr("start_time_time") = New Date(1, 1, 1, d.Hour, d.Minute, d.Second)
Dim dv As New DataView(dt)
dv.Sort = "start_time_time desc"
Sep 30, 2009 11:25 AM|eappell|LINK
Yep, that worked! Thanks!!