shajanjose
(Maria Jose Shajin L)
January 19, 2019, 7:02pm
1
Hi,
I am trying to filter the below data table based on ID Time column. I need to filter the Minimum date value from the same column,
ID
ID Time
Call Detail1
Call Detail2
Call Detail3
Call Detail4
Status
IncidentId
1
01/20/2018 00:07:04
jose
jose
jose
jose
Completed
1234
2
01/20/2018 00:07:05
kannan
kannan
kannan
kannan
Completed
2354
3
01/20/2018 00:07:06
NEW
4
01/20/2018 00:07:07
NEW
5
01/20/2018 00:07:08
NEW
I used the below logic but it was not working for me,
minDate = Convert.ToDateTime(dataTable.Compute(βMIN(TheDateColumnName)β, null))
Can anyone please help me on this?
Thanks.
I am not a C# expert but in the following paragraph I am trying to go over your assign statement
Convert.ToDateTime Basically you give it a string and it returns a DateTime value.
The Compute part applies an aggregate function to the specified column.
So my understanding is that you do compare strings and then you get the result (which is a string) and convert it to DateTime.
I would go by converting to DateTime first and then aggregating the MIN.
Maybe more experienced C# guys can confirm or infirm what I am saying β¦
arivu96
(Arivazhagan A)
January 20, 2019, 1:14am
3
Hi @shajanjose ,
Try below code to get minimum date from the column.
Convert.ToDateTime(((from DataRow dr in dt.Row orderby Convert.ToDateTime(dr("ID Time")) ascending select dr).FirstOrDefault(("ID Time")))
Regards,
Arivu
1 Like
Equivalent as Lambda expression, assuming the column is a DateTime (looks like it is the case)
dtmFirst = CDate(dt.AsEnumerable.OrderBy(Function(r)r("ID Time")).FirstOrDefault()("ID Time"))
Cheers
1 Like