简体   繁体   English

数据表计算:按日期过滤

[英]Datatable compute: filtering by date

I have a datatable with 2 columns: "amount" and "date" 我有一个包含2列的数据表:“金额”和“日期”

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 i等于nº月(1到12)
  • var _year equals nº year (example: 2011) var _year等于nº年(例如: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 is on VB.NET 2008. 这是在VB.NET 2008上。

I don't thing date works with LIJKE, why don't you use: 我不认为date可以和LIJKE一起使用,为什么不使用:

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. 另外,我大多在日期周围使用#号来强制使用英语符号,但是您必须自己进行试验。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM