emi_sastra
asked on
Get first date and last date from datatable.
Hi,
I have a datatable with transaction date on it, let's say TrsDate, and other data. The data is not sorted by TrsDate.
How to get the first transaction date and last transaction date from the datatable?
Thank you.
I have a datatable with transaction date on it, let's say TrsDate, and other data. The data is not sorted by TrsDate.
How to get the first transaction date and last transaction date from the datatable?
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi
is the TrsDate attribute type of date ? then sort the table and then select the first and last rows date
Dim sortstr As String = "TrsDate,otherColumn,other Column DESC"
YourDataTable.DefaultView. Sort = sortstr
Return YourDataTable
vbturbo
is the TrsDate attribute type of date ? then sort the table and then select the first and last rows date
Dim sortstr As String = "TrsDate,otherColumn,other
YourDataTable.DefaultView.
Return YourDataTable
vbturbo
ASKER
Hi Dhaest,
I've tried it. It works.
Thank you very much for your help.
I've tried it. It works.
Thank you very much for your help.
ASKER
Hi VBTurbo,
I am sorry, Dhaest has solved my problem.
Thank you.
I am sorry, Dhaest has solved my problem.
Thank you.
No problem at all.
I didn't see Dhaest post wich solves your question in many ways.
and then i would not even have posted my own comment
/vbturbo
I didn't see Dhaest post wich solves your question in many ways.
and then i would not even have posted my own comment
/vbturbo
ASKER
The hints (not exact command) provided by Dhaest obviously solve my problem.
1. use the DataTable.Compute function.
maximum: datatable.Compute("Max(myC olumn)", Nothing)
minimum: datatable.Compute("Min(myC olumn)", Nothing)
The second parameter is a filter, incase you want to limit the rows that are
applied to the aggregate function.
2. Create a dataview and order it
dv as new dataview(datatable)
dv.sort="StaffIdColumn, DESC"
Minimum --> dv(dv.count-1)("mycolumn")
Maximum --> dv(0)("mycolumn")
Thank you.
1. use the DataTable.Compute function.
maximum: datatable.Compute("Max(myC
minimum: datatable.Compute("Min(myC
The second parameter is a filter, incase you want to limit the rows that are
applied to the aggregate function.
2. Create a dataview and order it
dv as new dataview(datatable)
dv.sort="StaffIdColumn, DESC"
Minimum --> dv(dv.count-1)("mycolumn")
Maximum --> dv(0)("mycolumn")
Thank you.
ASKER
Could I use :
dim dteMinDate as date =datatable.Compute("Min(Tr
dim dteMaxDate as date =datatable.Compute("Max(Tr
Thank you.