[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Get first date and last date from datatable.

Posted on 2009-02-07
7
Medium Priority
?
282 Views
Last Modified: 2012-05-06
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.
0
Comment
Question by:emi_sastra
  • 4
  • 2
7 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 2000 total points
ID: 23582941
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
 
LVL 1

Author Comment

by:emi_sastra
ID: 23582957
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
 
LVL 18

Expert Comment

by:vbturbo
ID: 23583003
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:emi_sastra
ID: 23583015
Hi Dhaest,

I've tried it. It works.

Thank you very much for your help.

0
 
LVL 1

Author Comment

by:emi_sastra
ID: 23583017
Hi VBTurbo,

I am sorry, Dhaest has solved my problem.

Thank you.
0
 
LVL 18

Expert Comment

by:vbturbo
ID: 23583663
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
 
LVL 1

Author Comment

by:emi_sastra
ID: 23583756
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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question