Datatable compute: filtering by date
I have a datatable with 2 columns: "amount" and "date"
I want to sum "amount" by month & year.
I am trying this:
_tAmount = myDT.Compute("sum(amount)", "date LIKE '%/" & i & "/" & _year & "'")
where:
- var i equals a nº month ( 1 to 12)
- var _year equals nº year (example: 2011)
But not displays any results....How I can do it? What is wrong?
I am working with the spanish format (example day/month/year). But I have tried with the english format (month/day/year) and no results too.
This i开发者_高级运维s on VB.NET 2008.
I don't thing date works with LIJKE, why don't you use:
dim startdt as date = new date(_year, month, 1)
dim enddt as date = startdt.addmonth(1).adddays(-1)
_tAmount = myDT.Compute("sum(amount)", "date >= " & startdt & " AND date <= " & enddt)
This is out the top of my head, so check it yourself, but you should get the idea. Also, I use mostly the # sign around the dates to force english notation, but you'll have to experiment yourself.
精彩评论