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.
LVL 1
emi_sastraAsked:
Who is Participating?
 
DhaestConnect With a Mentor Commented:
I see several solutions:

1. use the DataTable.Compute function.

maximum:  datatable.Compute("Max(myColumn)", Nothing)
minimum: datatable.Compute("Min(myColumn)", 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")
0
 
emi_sastraAuthor Commented:
Hi Dhaest,

Could I use :

dim dteMinDate as date =datatable.Compute("Min(TrsDate)", Nothing)
dim dteMaxDate as date =datatable.Compute("Max(TrsDate)", Nothing)

Thank you.
0
 
vbturboCommented:
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,otherColumn DESC"
YourDataTable.DefaultView.Sort = sortstr
Return YourDataTable

vbturbo
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
emi_sastraAuthor Commented:
Hi Dhaest,

I've tried it. It works.

Thank you very much for your help.

0
 
emi_sastraAuthor Commented:
Hi VBTurbo,

I am sorry, Dhaest has solved my problem.

Thank you.
0
 
vbturboCommented:
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
0
 
emi_sastraAuthor Commented:
The hints (not exact command) provided by Dhaest obviously solve my problem.

1. use the DataTable.Compute function.

maximum:  datatable.Compute("Max(myColumn)", Nothing)
minimum: datatable.Compute("Min(myColumn)", 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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.