我需要从数据表中查询最近12个月的记录,但无法弄清楚VB.NET中的语法是什么。
在Microsoft SQL Server Management Studio中,以下查询有效:
[MyTable] >= dateadd(month,datediff(month,0,getdate())-12,0)
如何在VB.NET中实现这一目标?
我的查询很简单:
Dim Result As Integer = (From k In Model.Case
Join p In Model.Company ON k.Id_Case Equals p.Id_Case
Where k.EndingDate **Insert Code Here**).Count()
答案 0 :(得分:1)
长时间不使用Vb,请了解伪代码:
dim dtRange = DateTime.Now.AddMonths(-12)
'dim dtRange = DateTime.UtcNow.AddMonths(-12) 'For UTC time
Dim Result As Integer = (From k In Model.Case
Join p In Model.Company ON k.Id_Case Equals p.Id_Case
Where k.EndingDate >= dtRange).Count()